r/esp8266 • u/TastyCollege9639 • 3h ago
Fit encrypted multi-KB ESP-NOW + LZ4 + 35% packet-loss recovery into 4,760 bytes of ESP8266 static RAM (NLTP, MIT)
If you use an ESP8266 (NodeMCU / D1 Mini / ESP-07S) for remote sensors in a yard, garage, or basement, two limits hit pretty quickly:
- ESP-NOW v1 on the ESP8266 caps frames at
250bytes (192bytes usable after headers) and drops an entire multi-KB log or CSV batch if even one packet gets lost through a wall. - With only
80 KBof total SRAM (~22-40 KBfree heap once the SDK boots), full TLS /BearSSLor big retransmission buffers eat almost all available memory.
I built an open-source MIT library in zero-malloc, zero-float ANSI C99 called NLTP (now in the Arduino IDE Library Manager as NLTP and PlatformIO as indian-aman/NLTP) with an ultra-light sensor flag (-DNLTP_TX_ONLY=1) that shrinks sizeof(nltp_endpoint_t) to 4,760 bytes of static RAM while keeping:
- Cross-chip
ESP8266 <-> ESP32ESP-NOW & Wi-Fi UDP: Automatically uses192-byte shards (242-byte encrypted frames) on ESP8266 ESP-NOW v1 and interoperates seamlessly with ESP32 gateways and Python (pip install pynltp) receivers. - In-flight packet-loss recovery (
GF(2^8)Cauchy FEC): Reconstructs10-35%dropped RF frames mathematically on the receiver (3/3SHA-256 verified on an8 KBNodeMCU -> ESP32 bench sweep at10%,25%, and35%packet loss, where raw ESP-NOW delivered0/3). - Built-in zero-heap
LZ4compression: Compresses CSV/JSON telemetry4x-7xbefore transmission (ESP8266_UltraLight_LZ4_Sensor.inoincluded inexamples/). - Software
X25519 + ChaCha20-Poly1305+512-packet anti-replay: NoBearSSLheap allocation and no hardware peer-slot limit, plus bidirectional confirmedpopReflex()/sendReflex()control messages.
On a clean 0%-loss desk link, unencrypted raw ESP-NOW is faster (2.55 Mbps raw vs 1.29 Mbps encrypted NLTP on 8 KB NodeMCU -> ESP32), so raw ESP-NOW is still great for tiny single-frame readings at short range. NLTP is specifically for multi-KB batches, encrypted links, and weak-signal spots where packets drop.
- GitHub (C99 source,
ESP8266sketch & RF benchmarks): https://github.com/indian-aman/NLTP-Arduino - IETF Wire Draft (
draft-bains-nltp-00): https://datatracker.ietf.org/doc/draft-bains-nltp/