ESP_ERR_NVS_NOT_FOUND on a namespace that does exist
Posted: Fri Mar 20, 2020 4:24 pm
There something weird happening when I try to clear the WiFi credentials on NVS:
The commit happens successfully and I read back the values with an nvs_get_blob().
After a resetting ESP32 I get an ESP_ERR_NVS_NOT_FOUND when I try to read the committed data:
This only happens when I perform the NVS erase. and it seems to work after another nvs_commit().
What am I doing wrong? Should there be a nvs_deinit()?
TIA
Code: Select all
int err = nvs_flash_erase();
printf("\r\nErased NVS with: %d", err);
err = nvs_flash_init();
printf("\r\ninit: %d", err);
// then I try to re-save the application data
nvs_handle my_handle;
// Open
esp_err_t err = nvs_open(APP_SETTINGS_NAMESPACE, NVS_READWRITE, &my_handle);
ESP_ERROR_CHECK(err);
if (err != ESP_OK) {
return;
}
err = nvs_set_blob(my_handle, APP_SETTINGS_NAMESPACE, (void *) &(settings), sizeof(settings));
if (err != ESP_OK) return;
// Commit
err = nvs_commit(my_handle);
if (err != ESP_OK) return;
// Close
nvs_close(my_handle);
After a resetting ESP32 I get an ESP_ERR_NVS_NOT_FOUND when I try to read the committed data:
Code: Select all
nvs_handle handle;
// Open
esp_err_t err = nvs_open(APP_SETTINGS_NAMESPACE, NVS_READWRITE, &handle);
ESP_ERROR_CHECK(err);
if (err != ESP_OK) {
return;
}
size_t required_size;
err = nvs_get_blob(handle, APP_SETTINGS_NAMESPACE, NULL, &required_size);
if (err == ESP_ERR_NVS_NOT_FOUND)
{
printf(" NVS NOT FOUND");
}
What am I doing wrong? Should there be a nvs_deinit()?
TIA