Skip to content

Commit 2f0dc01

Browse files
committed
Merge branch 'feat/added_api_for_authmode_in_provisioning_demo' into 'master'
feat(provisioning): Addded api to set Authmode in provisioning Closes IDF-10973 See merge request espressif/esp-idf!33566
2 parents 1fa67f8 + 95f5b29 commit 2f0dc01

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

components/wifi_provisioning/include/wifi_provisioning/manager.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -36,6 +36,13 @@ typedef enum {
3636
*/
3737
WIFI_PROV_START,
3838

39+
/**
40+
* Emitted before accepting the wifi credentials to
41+
* set the wifi configurations according to requirement.
42+
* NOTE - In this case event_data shall be populated with a pointer to `wifi_config_t`.
43+
*/
44+
WIFI_PROV_SET_STA_CONFIG,
45+
3946
/**
4047
* Emitted when Wi-Fi AP credentials are received via `protocomm`
4148
* endpoint `wifi_config`. The event data in this case is a pointer

components/wifi_provisioning/src/manager.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -1240,6 +1240,9 @@ esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg)
12401240
RELEASE_LOCK(prov_ctx_lock);
12411241
return ESP_FAIL;
12421242
}
1243+
1244+
execute_event_cb(WIFI_PROV_SET_STA_CONFIG, (void *)wifi_cfg, sizeof(wifi_config_t));
1245+
12431246
if (prov_ctx->prov_state >= WIFI_PROV_STATE_CRED_RECV) {
12441247
ESP_LOGE(TAG, "Wi-Fi credentials already received by provisioning app");
12451248
RELEASE_LOCK(prov_ctx_lock);

examples/provisioning/wifi_prov_mgr/main/Kconfig.projbuild

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ menu "Example Configuration"
5858
default 1 if EXAMPLE_PROV_TRANSPORT_BLE
5959
default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP
6060

61+
config EXAMPLE_PROV_ENABLE_APP_CALLBACK
62+
bool "Enable provisioning manager app callback"
63+
default n
64+
help
65+
This is for advanced use-cases like modifying Wi-Fi configuration parameters. This
66+
executes a blocking app callback when any provisioning event is triggered.
67+
6168
config EXAMPLE_RESET_PROVISIONED
6269
bool
6370
default n
@@ -71,13 +78,13 @@ menu "Example Configuration"
7178
default y
7279
prompt "Reset provisioned credentials and state machine after session failure"
7380
help
74-
Enable reseting provisioned credentials and state machine after session failure.
81+
Enable resetting provisioned credentials and state machine after session failure.
7582
This will restart the provisioning service after retries are exhausted.
7683

7784
config EXAMPLE_PROV_MGR_MAX_RETRY_CNT
7885
int
7986
default 5
80-
prompt "Max retries before reseting provisioning state machine"
87+
prompt "Max retries before resetting provisioning state machine"
8188
depends on EXAMPLE_RESET_PROV_MGR_ON_FAILURE
8289
help
8390
Set the Maximum retry to avoid reconnecting to an inexistent AP or if credentials

examples/provisioning/wifi_prov_mgr/main/app_main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,34 @@ static void wifi_prov_print_qr(const char *name, const char *username, const cha
280280
ESP_LOGI(TAG, "If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", QRCODE_BASE_URL, payload);
281281
}
282282

283+
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
284+
void wifi_prov_app_callback(void *user_data, wifi_prov_cb_event_t event, void *event_data)
285+
{
286+
/**
287+
* This is blocking callback, any configurations that needs to be set when a particular
288+
* provisioning event is triggered can be set here.
289+
*/
290+
switch (event) {
291+
case WIFI_PROV_SET_STA_CONFIG: {
292+
/**
293+
* Wi-Fi configurations can be set here before the Wi-Fi is enabled in
294+
* STA mode.
295+
*/
296+
wifi_config_t *wifi_config = (wifi_config_t*)event_data;
297+
(void) wifi_config;
298+
break;
299+
}
300+
default:
301+
break;
302+
}
303+
}
304+
305+
const wifi_prov_event_handler_t wifi_prov_event_handler = {
306+
.event_cb = wifi_prov_app_callback,
307+
.user_data = NULL,
308+
};
309+
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
310+
283311
void app_main(void)
284312
{
285313
/* Initialize NVS partition */
@@ -327,6 +355,9 @@ void app_main(void)
327355
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
328356
.scheme = wifi_prov_scheme_softap,
329357
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
358+
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
359+
.app_event_handler = wifi_prov_event_handler,
360+
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
330361

331362
/* Any default scheme specific event handler that you would
332363
* like to choose. Since our example application requires

0 commit comments

Comments
 (0)