Skip to content

Commit

Permalink
wifi provisioning for efr32 in build command (#24036)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirsrin authored and pull[bot] committed Aug 4, 2023
1 parent 7b78193 commit 3f2c235
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 6 deletions.
21 changes: 20 additions & 1 deletion examples/light-switch-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ declare_args() {

# Argument to force enable WPA3 security
rs91x_wpa3_only = false

#default WiFi SSID
chip_default_wifi_ssid = ""

#default Wifi Password
chip_default_wifi_psk = ""
}

declare_args() {
Expand Down Expand Up @@ -90,8 +96,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

defines = []

# WiFi settings
if (chip_enable_wifi) {
if (chip_default_wifi_ssid != "") {
defines += [
"CHIP_ONNETWORK_PAIRING=1",
"CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"",
]
}
if (chip_default_wifi_psk != "") {
assert(chip_default_wifi_ssid != "",
"ssid can't be null if psk is provided")
defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ]
}
wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (lwip_ipv4) {
Expand Down Expand Up @@ -140,7 +159,7 @@ efr32_sdk("sdk") {
"${examples_common_plat_dir}",
]

defines = [
defines += [
"BOARD_ID=${silabs_board}",
"OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}",
]
Expand Down
21 changes: 20 additions & 1 deletion examples/lighting-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ declare_args() {

# Argument to force enable WPA3 security on rs91x
rs91x_wpa3_only = false

#default WiFi SSID
chip_default_wifi_ssid = ""

#default Wifi Password
chip_default_wifi_psk = ""
}

declare_args() {
Expand Down Expand Up @@ -90,13 +96,26 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

defines = []

# WiFi settings
if (chip_enable_wifi) {
# disabling LCD for MG24 for wifi
if (silabs_board == "BRD4186A" || silabs_board == "BRD4187A") {
show_qr_code = false
disable_lcd = true
}
if (chip_default_wifi_ssid != "") {
defines += [
"CHIP_ONNETWORK_PAIRING=1",
"CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"",
]
}
if (chip_default_wifi_psk != "") {
assert(chip_default_wifi_ssid != "",
"ssid can't be null if psk is provided")
defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ]
}
wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (lwip_ipv4) {
Expand Down Expand Up @@ -145,7 +164,7 @@ efr32_sdk("sdk") {
"${examples_common_plat_dir}",
]

defines = [
defines += [
"BOARD_ID=${silabs_board}",
"OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}",
]
Expand Down
21 changes: 20 additions & 1 deletion examples/lock-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ declare_args() {

# Argument to force enable WPA3 security
rs91x_wpa3_only = false

#default WiFi SSID
chip_default_wifi_ssid = ""

#default Wifi Password
chip_default_wifi_psk = ""
}

declare_args() {
Expand Down Expand Up @@ -90,8 +96,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

defines = []

# WiFi settings
if (chip_enable_wifi) {
if (chip_default_wifi_ssid != "") {
defines += [
"CHIP_ONNETWORK_PAIRING=1",
"CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"",
]
}
if (chip_default_wifi_psk != "") {
assert(chip_default_wifi_ssid != "",
"ssid can't be null if psk is provided")
defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ]
}
wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (lwip_ipv4) {
Expand Down Expand Up @@ -140,7 +159,7 @@ efr32_sdk("sdk") {
"${examples_common_plat_dir}",
]

defines = [
defines += [
"BOARD_ID=${silabs_board}",
"OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}",
]
Expand Down
21 changes: 20 additions & 1 deletion examples/thermostat/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ declare_args() {
# Argument to Disable IPv4 for wifi(rs911)
chip_enable_wifi_ipv4 = false

#default WiFi SSID
chip_default_wifi_ssid = ""

#default Wifi Password
chip_default_wifi_psk = ""

# Enable the temperature sensor
# Some boards do not have a temperature sensor
use_temp_sensor = silabs_board != "BRD2703A" && silabs_board != "BRD4319A"
Expand Down Expand Up @@ -91,8 +97,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

defines = []

# WiFi settings
if (chip_enable_wifi) {
if (chip_default_wifi_ssid != "") {
defines += [
"CHIP_ONNETWORK_PAIRING=1",
"CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"",
]
}
if (chip_default_wifi_psk != "") {
assert(chip_default_wifi_ssid != "",
"ssid can't be null if psk is provided")
defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ]
}
wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (lwip_ipv4) {
Expand Down Expand Up @@ -141,7 +160,7 @@ efr32_sdk("sdk") {
"${examples_common_plat_dir}",
]

defines = [
defines += [
"BOARD_ID=${silabs_board}",
"OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}",
]
Expand Down
21 changes: 20 additions & 1 deletion examples/window-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ declare_args() {

# Argument to force enable WPA3 security
rs91x_wpa3_only = false

#default WiFi SSID
chip_default_wifi_ssid = ""

#default Wifi Password
chip_default_wifi_psk = ""
}

declare_args() {
Expand Down Expand Up @@ -84,13 +90,26 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

defines = []

# WiFi settings
if (chip_enable_wifi) {
# disabling LCD for MG24 for wifi
if (silabs_board == "BRD4186C" || silabs_board == "BRD4187C") {
show_qr_code = false
disable_lcd = true
}
if (chip_default_wifi_ssid != "") {
defines += [
"CHIP_ONNETWORK_PAIRING=1",
"CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"",
]
}
if (chip_default_wifi_psk != "") {
assert(chip_default_wifi_ssid != "",
"ssid can't be null if psk is provided")
defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ]
}
wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
if (lwip_ipv4) {
Expand Down Expand Up @@ -139,7 +158,7 @@ efr32_sdk("sdk") {
"${examples_common_plat_dir}",
]

defines = [
defines += [
"BOARD_ID=${silabs_board}",
"OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}",
]
Expand Down
12 changes: 11 additions & 1 deletion src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ CHIP_ERROR SlWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC
mpScanCallback = nullptr;
mpConnectCallback = nullptr;

#ifdef CHIP_ONNETWORK_PAIRING
memcpy(&mSavedNetwork.ssid[0], CHIP_WIFI_SSID, sizeof(CHIP_WIFI_SSID));
memcpy(&mSavedNetwork.credentials[0], CHIP_WIFI_PSK, sizeof(CHIP_WIFI_PSK));
credentialsLen = sizeof(CHIP_WIFI_PSK);
ssidLen = sizeof(CHIP_WIFI_SSID);
mSavedNetwork.credentialsLen = credentialsLen;
mSavedNetwork.ssidLen = ssidLen;
mStagingNetwork = mSavedNetwork;
err = CHIP_NO_ERROR;
#else
// If reading fails, wifi is not provisioned, no need to go further.
err = SILABSConfig::ReadConfigValueStr(SILABSConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid),
ssidLen);
Expand All @@ -55,7 +65,7 @@ CHIP_ERROR SlWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC
mSavedNetwork.credentialsLen = credentialsLen;
mSavedNetwork.ssidLen = ssidLen;
mStagingNetwork = mSavedNetwork;

#endif
ConnectWiFiNetwork(mSavedNetwork.ssid, ssidLen, mSavedNetwork.credentials, credentialsLen);
return err;
}
Expand Down

0 comments on commit 3f2c235

Please sign in to comment.