Separate real time sampling from networking
Used FreeRTOS task boundaries to decouple sensor polling and network work, reducing shared mutable state and avoiding races between the two paths.
CASE STUDY · 2026
Keep field readings safe when the network disappears.
An ESP32 telemetry pipeline that buffers readings in SPI NOR flash during outages, then reconciles them with a concurrent Go service after reconnecting.
OVERVIEW
The ESP32 firmware separates sensor polling from network work with FreeRTOS tasks. When connectivity drops, readings are queued in an external SPI NOR flash circular buffer. Once the link returns, a Go backend receives records through a strict acknowledge and advance handshake so the device can resume from the oldest unsent record.
Sensor sampling must continue through a full network outage without races, silent data loss, or a corrupt backlog. Recovery also needs to respect TCP as a byte stream: the sender cannot discard a partial record and still expect the device to advance its queue safely.
HOW I APPROACHED IT
Used FreeRTOS task boundaries to decouple sensor polling and network work, reducing shared mutable state and avoiding races between the two paths.
Added a network finite state machine that detects link loss and appends telemetry to a circular queue in external SPI NOR flash rather than relying on volatile RAM.
On reconnect, the ESP32 sends the oldest record and advances the flash tail only after the Go service returns a single byte acknowledgement.
Changed the Go receive path to wait for a complete record before validating and acknowledging it, fixing partial reads that could leave the sender waiting indefinitely.
OUTCOME
Each queued record stays at the head of the flash backlog until the backend confirms a complete receive. This gives reconnect logic a clear checkpoint and prevents TCP fragmentation from being mistaken for a full telemetry record.
BUILT WITH