$ show antirez/freakwan
FreakWAN is a LoRa-based wide-area network (WAN) messaging system designed for ESP32 and T-ECHO devices. It implements a fully distributed, open chat network independent of internet or cellular infrastructure. The system supports plaintext and encrypted messaging, group chats, media sharing (small images), sensor data collection, and includes features like duty cycle tracking, automatic retransmission with ACK suppression, and neighborhood discovery via HELLO messages. The codebase is written in MicroPython (with a C port for T-ECHO) and is entirely self-contained, relying only on standard libraries. Architecturally, the application runs as a single asyncio event loop with multiple tasks for periodic message sending, HELLO advertising, serial input handling, and optional IRC/Telegram bot integration. The radio layer is abstracted behind SX1276 and SX1262 drivers, and the display uses a terminal-like Scroller view with splash screen and status icons. The protocol layer defines message types (Data, Ack, Hello, Ping, Pong) and supports encryption via AES-CBC with HMAC integrity. The repository is well-structured, with clear separation of concerns and reusable components that can be extracted for other projects.
The LLM identified 7 files worth highlighting for reuse:
Implements packet encryption/decryption using AES-128-CBC with HMAC-SHA256 integrity. Derives separate AES and MAC keys from a master key, handles padding, and provides a try-all-keys decryption mechanism. The design is tailored for constrained embedded devices and demonstrates careful trade-offs between security and packet size.
Provides an append-only log with fixed-size records using two files to avoid seeks. Writes are always appended to the shorter file, and the other file is deleted when the current file reaches the maximum length. This design minimizes filesystem operations and memory usage, making it ideal for flash-based storage in MicroPython.
Tracks radio duty cycle using a sliding window of time slots (default 4 slots of 15 minutes). Each slot records transmission time, and the average is calculated over valid slots. This is essential for regulatory compliance and efficient channel usage in LoRa networks.
Implements the FreakWAN Compressed Image (FCI) format, a lossless 1-bit image compression scheme using run-length encoding with short and long escapes. The decoder is single-pass and memory-efficient, rendering directly into a framebuffer. The design prioritizes simplicity and predictable compression ratios for small embedded images.
A clean, self-contained implementation of HMAC-SHA256 as specified in RFC 2104. Uses the MicroPython hashlib module and avoids unnecessary allocations. It is used by the keychain for message authentication and can be easily extracted for any project requiring HMAC.
Provides a BLE UART service (NUS-like) for MicroPython, enabling bidirectional serial communication over Bluetooth Low Energy. It handles advertising, connection management, and read/write callbacks. The implementation is based on MicroPython examples but cleaned up and well-documented, making it reusable for any BLE UART application.
A compact and efficient radix tree implementation for embedded systems. Supports insertion, deletion, lookup, and iteration with lexicographic ordering. The code is optimized for memory-constrained environments and includes a comprehensive iterator API. It is used in the C port for neighbor and ACK tracking and can be extracted as a standalone library.