How to re-provision ESP32 with wifi credentials?
Posted: Sat Jan 15, 2022 12:56 am
ESP documentation sates:
If provisioning state needs to be reset, any of the following approaches may be taken :
. Here's my code to erase NVS:
Any idea how to accomplish this simply after erasing associated part of NVS partition?
If provisioning state needs to be reset, any of the following approaches may be taken :
If I take the first approach (manually erase associated part of NVS partition) and then try to resend wifi credentials, I still get an error because prov_ctx->prov_state is WIFI_PROV_STATE_SUCCESS, so I'm unable to re-provision the chip with new credentials other than manually forcing a restart by callingthe associated part of NVS partition has to be erased manually
main application must implement some logic to call esp_wifi_ APIs for erasing the credentials at runtime
main application must implement some logic to force start the provisioning irrespective of the provisioning state
Code: Select all
ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key))
Code: Select all
ESP_ERROR_CHECK(nvs_flash_erase());
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
}
wifi_config_t wifi_cfg_empty;
memset(&wifi_cfg_empty, 0, sizeof(wifi_config_t));
esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_cfg_empty);