mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
wifi_provisioning: Add API to reset state if provisioning fails
This commit is contained in:
parent
59af9606e6
commit
f93fdda2ff
@ -553,6 +553,18 @@ 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 internal state machine and clear provisioned credentials.
|
||||
*
|
||||
* This API can be used to restart provisioning in case invalid credentials are entered.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Reset provisioning state machine successfully
|
||||
* - ESP_FAIL : Failed to reset provisioning state machine
|
||||
* - ESP_ERR_INVALID_STATE : Manager not initialized
|
||||
*/
|
||||
esp_err_t wifi_prov_mgr_reset_sm_state_on_failure(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1553,3 +1553,34 @@ void wifi_prov_mgr_stop_provisioning(void)
|
||||
|
||||
RELEASE_LOCK(prov_ctx_lock);
|
||||
}
|
||||
|
||||
esp_err_t wifi_prov_mgr_reset_sm_state_on_failure(void)
|
||||
{
|
||||
if (!prov_ctx_lock) {
|
||||
ESP_LOGE(TAG, "Provisioning manager not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
ACQUIRE_LOCK(prov_ctx_lock);
|
||||
|
||||
esp_err_t err = ESP_OK;
|
||||
if (prov_ctx->prov_state != WIFI_PROV_STATE_FAIL) {
|
||||
ESP_LOGE(TAG, "Trying reset when not in failure state. Current state: %d", prov_ctx->prov_state);
|
||||
err = ESP_ERR_INVALID_STATE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
wifi_config_t wifi_cfg = {0};
|
||||
|
||||
err = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to set wifi config, 0x%x", err);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
prov_ctx->prov_state = WIFI_PROV_STATE_STARTED;
|
||||
|
||||
exit:
|
||||
RELEASE_LOCK(prov_ctx_lock);
|
||||
return err;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user