esp-idf/examples/storage/nvs_rw_value_cxx
Jakob Hasse 1bf3ac5349 bugfix(nvs_flash): fixed wrong error check after open_nvs_handle
Closes https://github.com/espressif/esp-idf/issues/10240
2023-02-10 10:00:13 +08:00
..
main bugfix(nvs_flash): fixed wrong error check after open_nvs_handle 2023-02-10 10:00:13 +08:00
CMakeLists.txt [examples]: removed hyphens 2021-10-09 13:58:24 +08:00
Makefile [examples]: removed hyphens 2021-10-09 13:58:24 +08:00
README.md tools: replace _ with - in idf.py 2021-10-13 17:30:38 +08:00
nvs_rw_value_cxx_example_test.py ci: run Example_GENERIC for C3 2021-03-15 10:27:07 +08:00
sdkconfig.ci example_tests: Deletes usage esp32c3 ECO0 in CI (by default ECO3) 2021-09-24 13:55:07 +08:00

README.md

Non-Volatile Storage (NVS) C++ Read and Write Example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example demonstrates how to read and write a single integer value using NVS. It is essentially the same as the nvs_rw_value example. The only difference is that it uses the C++ NVS handle API. Please see nvs_rw_value README for more details about this example.

How to use example

Hardware required

This example does not require any special hardware, and can be run on any common development board.

Build and flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Example Output

First run:

Opening Non-Volatile Storage (NVS) handle... Done
Reading restart counter from NVS ... The value is not initialized yet!
Updating restart counter in NVS ... Done
Committing updates in NVS ... Done

Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.

Subsequent runs:

Opening Non-Volatile Storage (NVS) handle... Done
Reading restart counter from NVS ... Done
Restart counter = 1
Updating restart counter in NVS ... Done
Committing updates in NVS ... Done

Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.

Restart counter will increment on each run.

To reset the counter, erase the contents of flash memory using idf.py erase-flash, then upload the program again as described above.