mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
wifi_provisioning: Add API to reset state if provisioning fails
This commit is contained in:
parent
e005ec0899
commit
34bdbf9ee2
@ -563,6 +563,19 @@ esp_err_t wifi_prov_mgr_configure_sta(wifi_config_t *wifi_cfg);
|
||||
* - ESP_FAIL : Failed to reset provisioning config
|
||||
*/
|
||||
esp_err_t wifi_prov_mgr_reset_provisioning(void);
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -1578,3 +1578,34 @@ esp_err_t wifi_prov_mgr_reset_provisioning(void)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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