Any API to reset nvs to default setting?

axellin
Posts: 24
Joined: Mon Sep 17, 2018 9:09 am

Any API to reset nvs to default setting?

Postby axellin » Wed Nov 14, 2018 7:06 am

Hi,
I'm wondering how to reset nvs to default settings?
Some of the default settings are non-zero values.
So below code won't work because all fields become zero.
nvs_flash_erase();
nvs_flash_init();

ESP_Sprite
Posts: 2069
Joined: Thu Nov 26, 2015 4:08 am

Re: Any API to reset nvs to default setting?

Postby ESP_Sprite » Wed Nov 14, 2018 7:34 am

Erm, nope, if you erase the flash, it will nuke all the keys as well as values; reading a key should return an error, not a value of 0. Also, what default settings do you mean? NVS as-is has no concept of default values.

axellin
Posts: 24
Joined: Mon Sep 17, 2018 9:09 am

Re: Any API to reset nvs to default setting?

Postby axellin » Wed Nov 14, 2018 7:53 am

I use nvs_partition_gen.py to generate bin file from my csv file which includes the settings for my application.
And then using esptool.py to flash the bin file to flash.
My application will load the settings (follow the examples/storage/nvs_rw_value snip code) when booting.
The user may modify some setting at runtime.
However, I need a way to restore the original setting as the original bin file.
I'm not sure how to do this.

User avatar
loboris
Posts: 495
Joined: Wed Dec 21, 2016 7:40 pm

Re: Any API to reset nvs to default setting?

Postby loboris » Wed Nov 14, 2018 8:12 am

Include "default settings" as constants in your code or in another partition, than you can easily "restore" them
BDW, erasing Flash sets all bits to 1, not 0.

axellin
Posts: 24
Joined: Mon Sep 17, 2018 9:09 am

Re: Any API to reset nvs to default setting?

Postby axellin » Wed Nov 14, 2018 9:13 am

Hi loboris,
Thanks for your comments, I know how to do this now.

Who is online

Users browsing this forum: No registered users and 20 guests