How to initialize NVS on ESP32
First, include the ESP32 NVS library using:
init_nvs.cpp
#include <nvs.h>Globally, declare
nvs_handle_declaration.cpp
nvs_handle_t myNVS = 0;Then you can
init_nvs_function.cpp
void InitNVS() {
esp_err_t err;
if((err = nvs_open("MyLabel", NVS_READWRITE, &myNVS)) != ESP_OK) {
Serial.printf("Failed to open NVS: %s\r\n", esp_err_to_name(err));
return;
}
}You can choose MyLabel arbitrarily, as long as the string isn’t too long. My recommendation is to choose a unique identifier for your application.
Check out similar posts by category:
ESP8266/ESP32
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow