Merge branch 'feature/add_provisioning_rest_api' into 'master'

wifi_provisioning: add provisioning reset API

Closes IDF-1742

See merge request espressif/esp-idf!12405
This commit is contained in:
Mahavir Jain 2021-02-23 13:26:31 +00:00
commit 96b6e37346
4 changed files with 33 additions and 0 deletions

View File

@ -553,6 +553,16 @@ esp_err_t wifi_prov_mgr_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t *
*/
esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg);
/**
* @brief Reset Wi-Fi provisioning config
*
* Calling this API will restore WiFi stack persistent settings to default values.
*
* @return
* - ESP_OK : Reset provisioning config successfully
* - ESP_FAIL : Failed to reset provisioning config
*/
esp_err_t wifi_prov_mgr_reset_provisioning(void);
#ifdef __cplusplus
}
#endif

View File

@ -1553,3 +1553,15 @@ void wifi_prov_mgr_stop_provisioning(void)
RELEASE_LOCK(prov_ctx_lock);
}
esp_err_t wifi_prov_mgr_reset_provisioning(void)
{
esp_err_t ret = esp_wifi_restore();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "esp_wifi_restore fail, ret is %d", ret);
ret = ESP_FAIL;
}
return ret;
}

View File

@ -20,4 +20,11 @@ menu "Example Configuration"
default 1 if EXAMPLE_PROV_TRANSPORT_BLE
default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP
config EXAMPLE_RESET_PROVISIONED
bool
default n
prompt "Reset provisioned status of the device"
help
This erases the NVS to reset provisioned status of the device on every reboot.
Provisioned status is determined by the Wi-Fi STA configuration, saved on the NVS.
endmenu

View File

@ -185,9 +185,13 @@ void app_main(void)
ESP_ERROR_CHECK(wifi_prov_mgr_init(config));
bool provisioned = false;
#ifdef CONFIG_EXAMPLE_RESET_PROVISIONED
wifi_prov_mgr_reset_provisioning();
#else
/* Let's find out if the device is provisioned */
ESP_ERROR_CHECK(wifi_prov_mgr_is_provisioned(&provisioned));
#endif
/* If device is not yet provisioned start provisioning service */
if (!provisioned) {
ESP_LOGI(TAG, "Starting provisioning");