fixed NVS default read

master
Jan Umbach 2023-08-14 23:38:18 +02:00
parent 3c8fca8116
commit ffedc676cd
1 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,17 @@ esp_err_t readStorage(const char *key, char *out_value, size_t *length, char *de
esp_err_t ret = nvs_open("storage", NVS_READONLY, &my_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Error (%s) opening NVS handle!\n", esp_err_to_name(ret));
if (ret == ESP_ERR_NVS_NOT_FOUND)
{
ESP_LOGI(TAG, "The value is not initialized yet!\n");
goto SET_DEFUALT_VALUE;
}
else
{
ESP_LOGE(TAG, "Error (%s) reading!\n", esp_err_to_name(ret));
}
return ret;
}
else
@ -43,6 +53,8 @@ esp_err_t readStorage(const char *key, char *out_value, size_t *length, char *de
}
}
SET_DEFUALT_VALUE:
// if not found, set to default value
ret = nvs_open("storage", NVS_READWRITE, &my_handle);
if (ret != ESP_OK)