I can not read strings from the nvs partition after reboot, but I can see the written data if I dump the nvs partition over uart (with esp tool).
If I write int8 data then it works, but not with strings or blob data, I always become ESP_ERR_NVS_NOT_FOUND after reboot.
Here is my Debug output, after every reboot:
[0;31mE (485) eep: Error, NO data![0m
[0;32mI (485) eep: Setting Defaults ...[0m
[0;32mI (695) eep: Serial Number:'1234-1234'[0m
Her is my code:
- static const char* NvsESP_info = "espInfo";
- static const char* TAG = "eep";
- char Serial_Number[10];
- /******************************************************
- * Function Definitions
- ******************************************************/
- uint8_t device_settings_eep_get(void)
- {
- uint8_t result = NULL;
- memcpy(Serial_Number, "0000-0000", sizeof(Serial_Number)); // Reset Serial Number
- // Open
- nvs_handle my_handle;
- nvs_open("nvs", NVS_READWRITE, &my_handle);
- // Read
- size_t required_size = sizeof(Serial_Number);
- // Read Serial Number from nvs partition
- nvs_get_str(my_handle, NvsESP_info, &Serial_Number[0], &required_size);
- // Close
- nvs_close(my_handle);
- // Compare Serial Number from nvs partition with Default (1234-1234)
- if(!memcmp(&Serial_Number[0], "1234-1234", 9))
- {
- result = 1;
- ESP_LOGI(TAG, "Serial Number:'%s'", &Serial_Number[0]);
- }
- return result;
- }
- void device_settings_eep_set(const char *key, char *value)
- {
- nvs_handle my_handle;
- // Open
- nvs_open("nvs", NVS_READWRITE, &my_handle);
- // Write
- nvs_set_str(my_handle, key, value);
- // Commit
- nvs_commit(my_handle);
- // Close
- nvs_close(my_handle);
- }
- void device_settings_default_set(void)
- {
- ESP_LOGI(TAG, "Setting Defaults ...");
- nvs_flash_erase();
- nvs_flash_init();
- memcpy(Serial_Number, "1234-1234", sizeof(Serial_Number));
- device_settings_eep_set(NvsESP_info,(char*)&Serial_Number);
- }
- void Init_nvs_partition(void)
- {
- uint8_t value;
- nvs_flash_init();
- value = device_settings_eep_get();
- switch (value)
- {
- case 1:
- ESP_LOGE(TAG, "ESP nvs was successfully initialized!");
- break;
- default :
- ESP_LOGE(TAG, "Error, NO data!");
- device_settings_default_set();
- device_settings_eep_get();
- break;
- }
- }