Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

gianluca.siano
Posts: 12
Joined: Wed Sep 13, 2017 5:27 pm

Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

Postby gianluca.siano » Thu Jan 17, 2019 2:30 pm

Hi,

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:

Code: nvs_blob.c Select all


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;
}
}

gianluca.siano
Posts: 12
Joined: Wed Sep 13, 2017 5:27 pm

Re: Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

Postby gianluca.siano » Tue Jan 29, 2019 10:11 am

Still doesn't function.

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

Postby Sprite » Wed Jan 30, 2019 3:55 am

Code: Select all

    device_settings_eep_set(NvsESP_info, --> (char*)&Serial_Number <-- );
This probably doesn't do what you want it to do.

mauriciofarina
Posts: 2
Joined: Wed Apr 03, 2019 11:39 am

Re: Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

Postby mauriciofarina » Wed Nov 20, 2019 12:40 am

Hello!

Did you figure out how to solve it? I'm having the same problem. If I write a string or blob and read it without rebooting everything works great, but after rebooting they go missing...

Oldeneill
Posts: 1
Joined: Sun Nov 15, 2020 3:57 pm

Re: Can not read strings from nvs partition after reboot (ESP_ERR_NVS_NOT_FOUND)

Postby Oldeneill » Sun Nov 15, 2020 4:14 pm

Well aware that this thread is pretty dated - but it pops up high in Google, so I thought I'd share in case someone still stumbles accross this issue as I did today :D

Had the exact same issue (did the write/commit/close-thingey as per the documentation) but rebooting kept giving me ESP_ERR_NVS_NOT_FOUND.

Turns out there's a little Comma-seperated names of partitions to clear on factory reset in the menuconfig's Bootloader config that said nvs as value - nice little "Aaahhhhhhh!"-moment..

Obvious course of action - just remove those 3 nasty little characters and you should be good to go :mrgreen:

Side note: I'm not knowledgeable enough to tell if there's a good reason for clearing the default nvs partition after a factory reset; might be that the proper solution is to add a custom NVS partition via a partition csv or something. Going into the "cross that bridge when we get to it"-bin.

Who is online

Users browsing this forum: Baidu [Spider], ChatGPT-User and 2 guests