For a device that wakes up periodically to send data and then sleeps, which covers most of the battery IoT nodes, deep sleep is what you want. You call esp_deep_sleep_start() and the chip powers down to approximately 10 µA, keeping only the RTC oscillator ticking. Your specified wakeup source brings the chip back.

The GPIO16 trick for ESP8266: On the original ESP8266, you must wire GPIO16 to RST to wake from deep sleep via timer. The RTC fires a low pulse on GPIO16 which resets the chip. Forget this wire and your device sleeps forever.

On the ESP32, the timer wakeup is cleaner, no external wire needed. Call esp_sleep_enable_timer_wakeup(duration_in_microseconds) before esp_deep_sleep_start() and you're done.

Surviving Deep Sleep: RTC Memory

 Here's the subtle part: deep sleep kills your chip's state. All RAM is wiped. Your variables are gone. To preserve data across sleep cycles, use RTC memory, a small (16 KB) memory region powered by the RTC that survives deep sleep.

In Arduino: RTC_DATA_ATTR int bootCount = 0; that RTC_DATA_ATTR prefix stores the variable in RTC SLOW memory. Use it for boot counters, cached Wi-Fi credentials, last sensor value, or anything you need to remember between wakes.

 Cache your Wi-Fi BSSID and channel in RTC\_DATA\_ATTR variables. On subsequent wakes, pass them to WiFi.begin() explicitly to skip the channel scan. This alone cuts reconnect time from 3–5 seconds to under 1 second, a significant battery saving at scale.
Wireless & IOT

No comments yet. Be the first to comment!