ESP32 NVS Write Does Not Persist
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 NVS Write Does Not Persist. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 NVS write appears successful but data is lost after restart.
Quick Fix
Wrong
nvs_set_i32(handle, "counter", 42); // No commit!
Data written but lost after reset. Reads return old or default value.
Right
nvs_handle_t handle;
nvs_open("storage", NVS_READWRITE, &handle);
nvs_set_i32(handle, "counter", 42);
nvs_commit(handle); // REQUIRED to persist
nvs_close(handle);
Serial.println("Counter saved to NVS");
Counter saved to NVS
(Value persists across reboot)
Prevention
Always call nvs_commit() after writes to flush to flash. Open with NVS_READWRITE mode for writes. Write in batches and commit once. Do not commit too frequently (flash wear). Handle ESP_ERR_NVS_INVALID_HANDLE.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro