ESP32 RTC Memory Data Lost After Sleep
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 RTC Memory Data Lost After Sleep. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 data stored in RTC memory disappears after deep sleep wake.
Quick Fix
Wrong
int counter = 0; // Regular variable - lost on sleep
Counter resets to 0 after each deep sleep cycle.
Right
RTC_DATA_ATTR int bootCount = 0;
void setup() {
Serial.begin(115200);
bootCount++;
Serial.printf("Boot count: %d\n", bootCount);
esp_sleep_enable_timer_wakeup(5 * 1000000);
esp_deep_sleep_start();
}
Boot count: 1
Boot count: 2
Boot count: 3
(Count persists across deep sleep)
Prevention
Use RTC_DATA_ATTR to persist variables across deep sleep. RTC memory is 8KB total. Only simple data types survive (no String, no pointers). Use RTC memory for boot counters, calibration data, or sensor state.
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