Documentation
Onboarding
Getting Started
Power & Battery
Hardware & Components
Build & Assembly
Radio & RF Design
Frequencies & Regulations
Firmware & Software
USB & Connectivity
GPS & Navigation
Morse & Communication
Modes & Operation
Field Operations & Rescue
Building Effectively
Build Variants
Project & Reference
Docs Firmware & Software RTC RAM State

RTC RAM State

Edit on GitHub

What survives deep sleep: boot and TX counters, scan hit log, GPS fix cache and the emergency flag

RTC RAM State

Overview

The ESP32 keeps a small set of variables in RTC RAM, a memory region that stays powered during deep sleep and even across a full power cycle (as long as the RTC battery rail holds). This is how the beacon remembers its mode, its counters and its last GPS fix without touching flash.

Persistent Variables

VariableTypeMeaning
g_bootCycleuint32Increments every boot, survives deep sleep
g_txCyclesuint32Total TX cycles since manufacture
g_scanCyclesuint32Total scan cycles
g_scanHits[20]ScanHit[]Rolling log of the last 20 signal detections
g_scanHitCountuint8Current entries in g_scanHits (max 20)
g_currentModeDeviceModeActive mode, restored after deep sleep
g_emergencyActiveboolEmergency flag, persists across reboots
g_rtcLatdoubleLast known GPS latitude
g_rtcLngdoubleLast known GPS longitude
g_rtcFixValidboolWhether the RTC GPS cache is valid

ScanHit Structure

Each entry in the rolling hit log records:

FieldTypeDescription
freqfloatFrequency in MHz
rssiint16Peak RSSI in dBm during the dwell window
timestampuint32millis() at time of detection
labelchar[12]Signal class: WEAK / MEDIUM / STRONG

The log is a ring buffer: when it reaches 20 entries the oldest hit is overwritten. SEARCH mode shows the most recent hit on the display, and the dashboard renders the full history as RSSI bar charts.

Emergency Flag Persistence

g_emergencyActive is the most safety-critical RTC variable:

  • Setting EMERGENCY mode (long-press SW_MODE, or the dashboard /emergency endpoint) sets the flag before entering continuous TX.
  • Because the flag lives in RTC RAM, a battery swap or accidental reboot does not clear it - the device comes back up still transmitting.
  • The only ways to clear it are entering CONFIG mode and saving, or a factory reset.

Warning

If a beacon you are testing is stuck in EMERGENCY mode after a reboot, this flag is why. Enter CONFIG mode (hold SW_SEL 3 s) and save to clear it.

GPS Fix Cache

g_rtcLat, g_rtcLng and g_rtcFixValid store the last known position:

ConditionPayload coordinates
Fresh fix (less than 3 s old, at least 3 sats)Current fix
Stale fix (RTC cache from previous boot)Cached fix, marked stale
No fix and timeout expiredPSN UNKN

This means the beacon can transmit a position even on the first cycle after a cold boot, before the GPS has re-acquired - the coordinates are the last place the operator was known to be.