examples/storage/nvs/nvs_console/README.md
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 |
|---|
This example demonstrates how to use Non-Volatile Storage (NVS) through an interactive console interface. It provides a set of commands to read, write, and manage data in NVS.
This example can run on any ESP32 family development board.
The example can be configured through menuconfig:
CONFIG_CONSOLE_STORE_HISTORY)Build the project and flash it to the board, then run monitor tool to view serial output:
idf.py -p PORT flash monitor
(Replace PORT with the name of the serial port to use.)
The following commands are available:
NVS Operations:
nvs_namespace <namespace> - Set current namespace
nvs_namespace storagenvs_set <key> <type> -v <value> - Set a value in NVS
nvs_set counter i32 -v 42nvs_set name str -v "esp"nvs_set blob_val blob -v "657370" - To set a blob value, provide the hex representation of the data you want to store. For example, 65 (e), 73 (s), 70 (p).nvs_get <key> - Get a value from NVS
nvs_get counternvs_erase <key> - Erase a key from NVS
nvs_erase counternvs_list <partition> [-n <namespace>] [-t <type>] - List stored key-value pairs stored in NVS. Use default partition name 'nvs' for listing the stored data.
nvs_list nvs - This command lists all namespaces and their stored key-value pairs in the 'nvs' partition.nvs_list nvs -n storage -t i8nvs_erase_namespace <namespace> - Erases specified namespace
nvs_erase_namespace storageSystem Commands:
help - List all commandsfree - Get the current size of free heap memoryrestart - Software reset of the chipversion - Get the chip info together with ESP-IDF version used in the applicationheap - Get minimum size of free heap memory that was available during program execution...
NVS Console Example
-------------------
Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.
Press Ctrl+C to exit the console.
nvs> version
IDF Version:v5.5-dev-2627-g2cbfce97768-dirt
Chip info:
model:ESP32
cores:2
feature:/802.11bgn/BLE/BT/External-Flash:2 MB
revision number:0
nvs> free
298172
nvs> heap
min heap size: 298156
nvs> nvs_list nvs
namespace 'storage_1', key 'u8_key', type 'u8'
namespace 'storage_1', key 'i8_key', type 'i8'
namespace 'storage_1', key 'u16_key', type 'u16'
namespace 'storage_2', key 'u32_key', type 'u32'
namespace 'storage_2', key 'i32_key', type 'i32'
namespace 'storage_2', key 'str_key', type 'str'
nvs> nvs_namespace storage_1
I (85497) cmd_nvs: Namespace set to 'storage_1'
nvs> nvs_get i8_key i8
-128
nvs> nvs_set i8_key i8 -v -50
I (233297) cmd_nvs: Value stored under key 'i8_key'
nvs> nvs_get i8_key i8
-50
nvs>
...