NVS stands for Non-volatile Storage
This library is designed to store key-value pairs to flash
By default The flash has an NVS partition at 0x9000 offset address, it contains the wifi data
We will go through this example to make use of the NVS memory
https://github.com/espressif/esp-idf/tree/master/examples/storage/nvs_rw_value
At first NVS partition is initialized, if there are no free pages then it is erased and re-initialized again
Multiple internal ESP-IDF and 3rd Party apps can store key-value pairs in the NVS partition using this library. in order to reduce possible conflicts on key names, the library provides a way for the user to store values by creating Namespace first.
At first, create a handle to reference the further usage of NVS
Then open the namespace
To set/ save a value for a key use the following function
After writing a value you must commit to ensuring changes are written to flash storage
To read from the key use the following function
After usage close the handle
Build and run the example on the ESP32
The output of the program :
Please take a look at the following snippet from Espressif. It has some important info on the partition
Wrapping the NVS in, we can easily create a custom database library. I have designed a lot of databases on top of NVS. There are some design patterns that work by creating a cache in RAM thereby preventing excessive write cycles to NVS. this is also known as wear-leveling
0 comments:
Post a Comment