Skip to content

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.
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

### How much RTC memory is available?

ESP32 has 8KB of RTC slow memory. Variables declared with RTC_DATA_ATTR go here.

What data types can survive sleep?

POD types (int, float, structs without pointers). Arrays work. Strings and objects with dynamic allocation do not survive.

Can I keep Wi-Fi credentials in RTC memory?

Yes. Store SSID/password in RTC memory for faster reconnection. Reconnect from RTC data takes ~1s vs ~5s from fresh connection.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro