forked from espressif/esp-idf
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
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -36,6 +36,13 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
WIFI_PROV_START,
|
WIFI_PROV_START,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted before accepting the wifi credentials to
|
||||||
|
* set the wifi configurations according to requirement.
|
||||||
|
* NOTE - In this case event_data shall be populated with a pointer to `wifi_config_t`.
|
||||||
|
*/
|
||||||
|
WIFI_PROV_SET_STA_CONFIG,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when Wi-Fi AP credentials are received via `protocomm`
|
* Emitted when Wi-Fi AP credentials are received via `protocomm`
|
||||||
* endpoint `wifi_config`. The event data in this case is a pointer
|
* endpoint `wifi_config`. The event data in this case is a pointer
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -1240,6 +1240,9 @@ esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg)
|
|||||||
RELEASE_LOCK(prov_ctx_lock);
|
RELEASE_LOCK(prov_ctx_lock);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
execute_event_cb(WIFI_PROV_SET_STA_CONFIG, (void *)wifi_cfg, sizeof(wifi_config_t));
|
||||||
|
|
||||||
if (prov_ctx->prov_state >= WIFI_PROV_STATE_CRED_RECV) {
|
if (prov_ctx->prov_state >= WIFI_PROV_STATE_CRED_RECV) {
|
||||||
ESP_LOGE(TAG, "Wi-Fi credentials already received by provisioning app");
|
ESP_LOGE(TAG, "Wi-Fi credentials already received by provisioning app");
|
||||||
RELEASE_LOCK(prov_ctx_lock);
|
RELEASE_LOCK(prov_ctx_lock);
|
||||||
|
@@ -58,6 +58,13 @@ menu "Example Configuration"
|
|||||||
default 1 if EXAMPLE_PROV_TRANSPORT_BLE
|
default 1 if EXAMPLE_PROV_TRANSPORT_BLE
|
||||||
default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP
|
default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||||
|
|
||||||
|
config EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||||
|
bool "Enable provisioning manager app callback"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
This is for advanced use-cases like modifying Wi-Fi configuration parameters. This
|
||||||
|
executes a blocking app callback when any provisioning event is triggered.
|
||||||
|
|
||||||
config EXAMPLE_RESET_PROVISIONED
|
config EXAMPLE_RESET_PROVISIONED
|
||||||
bool
|
bool
|
||||||
default n
|
default n
|
||||||
@@ -71,13 +78,13 @@ menu "Example Configuration"
|
|||||||
default y
|
default y
|
||||||
prompt "Reset provisioned credentials and state machine after session failure"
|
prompt "Reset provisioned credentials and state machine after session failure"
|
||||||
help
|
help
|
||||||
Enable reseting provisioned credentials and state machine after session failure.
|
Enable resetting provisioned credentials and state machine after session failure.
|
||||||
This will restart the provisioning service after retries are exhausted.
|
This will restart the provisioning service after retries are exhausted.
|
||||||
|
|
||||||
config EXAMPLE_PROV_MGR_MAX_RETRY_CNT
|
config EXAMPLE_PROV_MGR_MAX_RETRY_CNT
|
||||||
int
|
int
|
||||||
default 5
|
default 5
|
||||||
prompt "Max retries before reseting provisioning state machine"
|
prompt "Max retries before resetting provisioning state machine"
|
||||||
depends on EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
depends on EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
||||||
help
|
help
|
||||||
Set the Maximum retry to avoid reconnecting to an inexistent AP or if credentials
|
Set the Maximum retry to avoid reconnecting to an inexistent AP or if credentials
|
||||||
|
@@ -280,6 +280,34 @@ static void wifi_prov_print_qr(const char *name, const char *username, const cha
|
|||||||
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||||
|
void wifi_prov_app_callback(void *user_data, wifi_prov_cb_event_t event, void *event_data)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This is blocking callback, any configurations that needs to be set when a particular
|
||||||
|
* provisioning event is triggered can be set here.
|
||||||
|
*/
|
||||||
|
switch (event) {
|
||||||
|
case WIFI_PROV_SET_STA_CONFIG: {
|
||||||
|
/**
|
||||||
|
* Wi-Fi configurations can be set here before the Wi-Fi is enabled in
|
||||||
|
* STA mode.
|
||||||
|
*/
|
||||||
|
wifi_config_t *wifi_config = (wifi_config_t*)event_data;
|
||||||
|
(void) wifi_config;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const wifi_prov_event_handler_t wifi_prov_event_handler = {
|
||||||
|
.event_cb = wifi_prov_app_callback,
|
||||||
|
.user_data = NULL,
|
||||||
|
};
|
||||||
|
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
/* Initialize NVS partition */
|
/* Initialize NVS partition */
|
||||||
@@ -327,6 +355,9 @@ void app_main(void)
|
|||||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||||
.scheme = wifi_prov_scheme_softap,
|
.scheme = wifi_prov_scheme_softap,
|
||||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||||
|
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||||
|
.app_event_handler = wifi_prov_event_handler,
|
||||||
|
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
|
||||||
|
|
||||||
/* Any default scheme specific event handler that you would
|
/* Any default scheme specific event handler that you would
|
||||||
* like to choose. Since our example application requires
|
* like to choose. Since our example application requires
|
||||||
|
Reference in New Issue
Block a user