Skip to content

Commit a69d83c

Browse files
committed
[NXP] Adding wifi_connect module
Signed-off-by: Martin Girardot <martin.girardot@nxp.com>
1 parent 433c23d commit a69d83c

File tree

6 files changed

+129
-126
lines changed

6 files changed

+129
-126
lines changed

examples/all-clusters-app/nxp/rt/rw61x/BUILD.gn

+11-41
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ assert(target_os == "freertos")
3535
assert(nxp_platform == "rt/rw61x")
3636

3737
declare_args() {
38-
# Allows to start the tcp download test app
39-
tcp_download = false
4038

41-
# Allows to start the wifi connect test app
42-
wifi_connect = false
43-
44-
# The 2 params below are used only if tcp_download or wifi_connect are true, otherwise they're unused.
45-
wifi_ssid = ""
46-
wifi_password = ""
39+
# Allows to connect to a predefine Wi-Fi network at boot
40+
wifi_auto_connect_at_boot = false
41+
wifi_auto_connect_at_boot_ssid = ""
42+
wifi_auto_connect_at_boot_password = ""
4743

4844
# Setup discriminator as argument
4945
setup_discriminator = 3840
@@ -53,10 +49,6 @@ example_platform_dir =
5349
"${nxp_sdk_matter_support_root}/examples/platform/${nxp_platform}"
5450
common_example_dir = "${chip_root}/examples/platform/nxp/common"
5551

56-
if (tcp_download == true && wifi_connect == true) {
57-
assert("Cannot enable tcp_download and wifi_connect at the same time!")
58-
}
59-
6052
app_common_folder = "all-clusters-app/all-clusters-common"
6153

6254
# Create here the SDK instance.
@@ -213,42 +205,20 @@ rt_executable("all_cluster_app") {
213205
]
214206
}
215207

216-
if (wifi_connect) {
208+
if (wifi_auto_connect_at_boot) {
209+
assert(wifi_auto_connect_at_boot_ssid != "" && wifi_auto_connect_at_boot_password != "",
210+
"WiFi SSID and password must be specified at build time!")
211+
217212
defines += [
218-
"WIFI_CONNECT_TASK=1",
219-
"WIFI_CONNECT=1",
213+
"CONFIG_CHIP_APP_WIFI_CONNECT_AT_BOOT=1",
214+
"CONFIG_CHIP_APP_WIFI_SSID=\"${wifi_auto_connect_at_boot_ssid}\"",
215+
"CONFIG_CHIP_APP_WIFI_PASSWORD=\"${wifi_auto_connect_at_boot_password}\"",
220216
]
221217

222-
if (!chip_enable_matter_cli) {
223-
assert(wifi_ssid != "" && wifi_password != "",
224-
"WiFi SSID and password must be specified at build time!")
225-
}
226-
227-
if (wifi_ssid != "") {
228-
defines += [ "WIFI_SSID=\"${wifi_ssid}\"" ]
229-
}
230-
231-
if (wifi_password != "") {
232-
defines += [ "WIFI_PASSWORD=\"${wifi_password}\"" ]
233-
}
234-
235218
include_dirs += [ "${common_example_dir}/wifi_connect/include" ]
236219
sources += [ "${common_example_dir}/wifi_connect/source/WifiConnect.cpp" ]
237220
}
238221

239-
if (tcp_download) {
240-
defines += [ "CONFIG_CHIP_TCP_DOWNLOAD=1" ]
241-
defines += [
242-
"WIFI_CONNECT=1",
243-
"WIFI_SSID=\"${wifi_ssid}\"",
244-
"WIFI_PASSWORD=\"${wifi_password}\"",
245-
]
246-
247-
include_dirs += [ "${common_example_dir}/tcp_download_test/include" ]
248-
sources +=
249-
[ "${common_example_dir}/tcp_download_test/source/TcpDownload.cpp" ]
250-
}
251-
252222
# In case a dedicated assert function needs to be supported the flag sdk_fsl_assert_support should be set to false
253223
# The would add to the build a dedicated application assert implementation.
254224
if (!sdk_fsl_assert_support) {

examples/laundry-washer-app/nxp/rt/rw61x/BUILD.gn

+11-42
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ assert(target_os == "freertos")
3535
assert(nxp_platform == "rt/rw61x")
3636

3737
declare_args() {
38-
# Allows to start the tcp download test app
39-
tcp_download = false
40-
41-
# Allows to start the wifi connect test app
42-
wifi_connect = false
43-
44-
# The 2 params below are used only if tcp_download or wifi_connect are true, otherwise they're unused.
45-
wifi_ssid = ""
46-
wifi_password = ""
38+
# Allows to connect to a predefine Wi-Fi network at boot
39+
wifi_auto_connect_at_boot = false
40+
wifi_auto_connect_at_boot_ssid = ""
41+
wifi_auto_connect_at_boot_password = ""
4742

4843
# Setup discriminator as argument
4944
setup_discriminator = 3840
@@ -53,10 +48,6 @@ example_platform_dir =
5348
"${nxp_sdk_matter_support_root}/examples/platform/${nxp_platform}"
5449
common_example_dir = "${chip_root}/examples/platform/nxp/common"
5550

56-
if (tcp_download == true && wifi_connect == true) {
57-
assert("Cannot enable tcp_download and wifi_connect at the same time!")
58-
}
59-
6051
# Use NXP custom zap files for laundry-washer device-type
6152
app_common_folder = "laundry-washer-app/nxp/zap"
6253

@@ -218,42 +209,20 @@ rt_executable("laundry-washer") {
218209
]
219210
}
220211

221-
if (wifi_connect) {
212+
if (wifi_auto_connect_at_boot) {
213+
assert(wifi_auto_connect_at_boot_ssid != "" && wifi_auto_connect_at_boot_password != "",
214+
"WiFi SSID and password must be specified at build time!")
215+
222216
defines += [
223-
"WIFI_CONNECT_TASK=1",
224-
"WIFI_CONNECT=1",
217+
"CONFIG_CHIP_APP_WIFI_CONNECT_AT_BOOT=1",
218+
"CONFIG_CHIP_APP_WIFI_SSID=\"${wifi_auto_connect_at_boot_ssid}\"",
219+
"CONFIG_CHIP_APP_WIFI_PASSWORD=\"${wifi_auto_connect_at_boot_password}\"",
225220
]
226221

227-
if (!chip_enable_matter_cli) {
228-
assert(wifi_ssid != "" && wifi_password != "",
229-
"WiFi SSID and password must be specified at build time!")
230-
}
231-
232-
if (wifi_ssid != "") {
233-
defines += [ "WIFI_SSID=\"${wifi_ssid}\"" ]
234-
}
235-
236-
if (wifi_password != "") {
237-
defines += [ "WIFI_PASSWORD=\"${wifi_password}\"" ]
238-
}
239-
240222
include_dirs += [ "${common_example_dir}/wifi_connect/include" ]
241223
sources += [ "${common_example_dir}/wifi_connect/source/WifiConnect.cpp" ]
242224
}
243225

244-
if (tcp_download) {
245-
defines += [ "CONFIG_CHIP_TCP_DOWNLOAD=1" ]
246-
defines += [
247-
"WIFI_CONNECT=1",
248-
"WIFI_SSID=\"${wifi_ssid}\"",
249-
"WIFI_PASSWORD=\"${wifi_password}\"",
250-
]
251-
252-
include_dirs += [ "${common_example_dir}/tcp_download_test/include" ]
253-
sources +=
254-
[ "${common_example_dir}/tcp_download_test/source/TcpDownload.cpp" ]
255-
}
256-
257226
# In case a dedicated assert function needs to be supported the flag sdk_fsl_assert_support should be set to false
258227
# The would add to the build a dedicated application assert implementation.
259228
if (!sdk_fsl_assert_support) {

examples/platform/nxp/common/app_task/source/AppTaskBase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void chip::NXP::App::AppTaskBase::InitServer(intptr_t arg)
213213
#endif
214214

215215
#if CONFIG_CHIP_APP_WIFI_CONNECT_AT_BOOT
216-
WifiConnectAtboot();
216+
VerifyOrDie(WifiConnectAtboot(chip::NXP::App::GetAppTask().GetWifiDriverInstance()) == CHIP_NO_ERROR);
217217
#endif
218218

219219
#if CHIP_DEVICE_CONFIG_ENABLE_TBR
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @file WifiConnect.h
21+
*
22+
* Wi-Fi Connect Module allowing to join a pre-defined Wi-Fi network
23+
*
24+
**/
25+
26+
#pragma once
27+
28+
#include <platform/NetworkCommissioning.h>
29+
30+
namespace chip {
31+
namespace NXP {
32+
namespace App {
33+
34+
/*
35+
* Function allowing to join a Wi-Fi network based on Wi-Fi build credentials
36+
* Must be called after completing Wi-Fi driver initialization
37+
*/
38+
CHIP_ERROR WifiConnectAtboot(chip::DeviceLayer::NetworkCommissioning::WiFiDriver * wifiDriver);
39+
40+
} // namespace App
41+
} // namespace NXP
42+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "WifiConnect.h"
20+
#include <lib/support/Span.h>
21+
#include <platform/ConnectivityManager.h>
22+
#include <platform/NetworkCommissioning.h>
23+
24+
namespace chip {
25+
namespace NXP {
26+
namespace App {
27+
28+
CHIP_ERROR WifiConnectAtboot(chip::DeviceLayer::NetworkCommissioning::WiFiDriver * wifiDriver)
29+
{
30+
VerifyOrReturnError(wifiDriver != nullptr, CHIP_ERROR_NOT_IMPLEMENTED);
31+
32+
/* In case WiFi connect at boot is enabled try to set SSID to the predefined value */
33+
ByteSpan ssidSpan = ByteSpan(Uint8::from_const_char(CONFIG_CHIP_APP_WIFI_SSID), strlen(CONFIG_CHIP_APP_WIFI_SSID));
34+
ByteSpan passwordSpan = ByteSpan(Uint8::from_const_char(CONFIG_CHIP_APP_WIFI_PASSWORD), strlen(CONFIG_CHIP_APP_WIFI_PASSWORD));
35+
VerifyOrReturnError(IsSpanUsable(ssidSpan) && IsSpanUsable(passwordSpan), CHIP_ERROR_INVALID_ARGUMENT);
36+
37+
chip::DeviceLayer::NetworkCommissioning::NetworkIterator * networks = wifiDriver->GetNetworks();
38+
/* In case Wi-Fi driver has already Wi-Fi network information, skip the connect stage */
39+
if (networks == nullptr || networks->Count() == 0)
40+
{
41+
uint8_t networkIndex;
42+
chip::MutableCharSpan debugText;
43+
chip::DeviceLayer::NetworkCommissioning::Status status =
44+
wifiDriver->AddOrUpdateNetwork(ssidSpan, passwordSpan, debugText, networkIndex);
45+
VerifyOrReturnError(status == chip::DeviceLayer::NetworkCommissioning::Status::kSuccess, CHIP_ERROR_CONNECTION_ABORTED);
46+
wifiDriver->ConnectNetwork(ssidSpan, nullptr);
47+
}
48+
return CHIP_NO_ERROR;
49+
}
50+
51+
} // namespace App
52+
} // namespace NXP
53+
} // namespace chip

examples/thermostat/nxp/rt/rw61x/BUILD.gn

+11-42
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ assert(target_os == "freertos")
3535
assert(nxp_platform == "rt/rw61x")
3636

3737
declare_args() {
38-
# Allows to start the tcp download test app
39-
tcp_download = false
40-
41-
# Allows to start the wifi connect test app
42-
wifi_connect = false
43-
44-
# The 2 params below are used only if tcp_download or wifi_connect are true, otherwise they're unused.
45-
wifi_ssid = ""
46-
wifi_password = ""
38+
# Allows to connect to a predefine Wi-Fi network at boot
39+
wifi_auto_connect_at_boot = false
40+
wifi_auto_connect_at_boot_ssid = ""
41+
wifi_auto_connect_at_boot_password = ""
4742

4843
# Setup discriminator as argument
4944
setup_discriminator = 3840
@@ -55,10 +50,6 @@ example_platform_dir =
5550
"${nxp_sdk_matter_support_root}/examples/platform/${nxp_platform}"
5651
common_example_dir = "${chip_root}/examples/platform/nxp/common"
5752

58-
if (tcp_download == true && wifi_connect == true) {
59-
assert("Cannot enable tcp_download and wifi_connect at the same time!")
60-
}
61-
6253
# Use NXP custom zap files for thermostatdevice-types
6354
app_common_folder = "thermostat/nxp/zap"
6455

@@ -227,42 +218,20 @@ rt_executable("thermostat") {
227218
]
228219
}
229220

230-
if (wifi_connect) {
221+
if (wifi_auto_connect_at_boot) {
222+
assert(wifi_auto_connect_at_boot_ssid != "" && wifi_auto_connect_at_boot_password != "",
223+
"WiFi SSID and password must be specified at build time!")
224+
231225
defines += [
232-
"WIFI_CONNECT_TASK=1",
233-
"WIFI_CONNECT=1",
226+
"CONFIG_CHIP_APP_WIFI_CONNECT_AT_BOOT=1",
227+
"CONFIG_CHIP_APP_WIFI_SSID=\"${wifi_auto_connect_at_boot_ssid}\"",
228+
"CONFIG_CHIP_APP_WIFI_PASSWORD=\"${wifi_auto_connect_at_boot_password}\"",
234229
]
235230

236-
if (!chip_enable_matter_cli) {
237-
assert(wifi_ssid != "" && wifi_password != "",
238-
"WiFi SSID and password must be specified at build time!")
239-
}
240-
241-
if (wifi_ssid != "") {
242-
defines += [ "WIFI_SSID=\"${wifi_ssid}\"" ]
243-
}
244-
245-
if (wifi_password != "") {
246-
defines += [ "WIFI_PASSWORD=\"${wifi_password}\"" ]
247-
}
248-
249231
include_dirs += [ "${common_example_dir}/wifi_connect/include" ]
250232
sources += [ "${common_example_dir}/wifi_connect/source/WifiConnect.cpp" ]
251233
}
252234

253-
if (tcp_download) {
254-
defines += [ "CONFIG_CHIP_TCP_DOWNLOAD=1" ]
255-
defines += [
256-
"WIFI_CONNECT=1",
257-
"WIFI_SSID=\"${wifi_ssid}\"",
258-
"WIFI_PASSWORD=\"${wifi_password}\"",
259-
]
260-
261-
include_dirs += [ "${common_example_dir}/tcp_download_test/include" ]
262-
sources +=
263-
[ "${common_example_dir}/tcp_download_test/source/TcpDownload.cpp" ]
264-
}
265-
266235
# In case a dedicated assert function needs to be supported the flag sdk_fsl_assert_support should be set to false
267236
# The would add to the build a dedicated application assert implementation.
268237
if (!sdk_fsl_assert_support) {

0 commit comments

Comments
 (0)