In this article, we are going to learn how to use NVS to store key-value pairs that persist even if our board is restarted.
What is NVS
NVS stands for Non-Volatile Storage. It’s a library that allows us to store key-value pairs in flash memory.
ESP-IDF projects partition the boards flash into different sections. Among these partitions, there is one where our application code lives and there is another section we can use to store any data we want. This section is called the data
partition, and that’s what NVS uses for storage.
Flash models
Different development boards might come with different models of flash memory. I bought a cheap development board from my local electronics shop, and it didn’t include much information about the specs, so I didn’t really know what flash it uses.
Luckily, ESP-IDF comes with a tool we can use to get information about our flash memory:
1
| esptool.py --port /dev/ttyUSB0 flash_id
|
The output for my board included this:
1
2
3
| Manufacturer: 5e
Device: 4016
Detected flash size: 4MB
|