$ show SignalK/SensESP
SensESP is an embedded firmware framework for ESP32 microcontrollers that enables building custom marine sensors that communicate via the Signal K protocol. It provides a complete pipeline from physical sensor reading (via Arduino libraries or built-in ADC/digital inputs) through data transformation (30+ composable transforms like linear scaling, moving average, hysteresis, curve interpolation) to publishing over WebSocket to a Signal K server. The framework includes a full web-based configuration UI (Preact/Bootstrap) served directly from the device, WiFi/Ethernet provisioning with captive portal, OTA updates, and a REST API for device management. Architecture follows a reactive dataflow pattern: sensors produce typed values that flow through transform chains to consumers (Signal K output, UI, logging). The core is built on ReactESP event loop, with observable/value producer/consumer abstractions enabling type-safe connections. Notable components include a TOFU certificate pinning system for secure Signal K connections, a circular log buffer with snapshot cursor for the web UI, and a smart switch controller supporting local and remote actuation with double-click sync. The codebase is well-structured with unit tests for transforms, metadata, and networking components, though some deprecated APIs and a large god object (SensESPApp) indicate areas for refactoring.
The LLM identified 7 files worth highlighting for reuse:
Implements the Observable base class with attach/detach lifecycle and notification. Used as the foundation for all reactive data flow in SensESP. Self-contained and could be extracted for any embedded project needing a lightweight observer pattern.
Typed ValueProducer template that connects to ValueConsumer instances via connect_to(). Enables compile-time type checking in sensor data pipelines. Demonstrates clean C++ template usage for safe data routing.
Allows users to define inline transforms via lambda functions with up to 6 parameters, automatically generating JSON configuration schema. Reduces boilerplate for simple sensor processing. The variadic template approach (despite code duplication) is practical for constrained embedded compilers.
In-memory circular log buffer with cursor-based snapshot retrieval, gap detection, and ANSI escape stripping. Handles memory pressure with backoff. Designed for embedded web UI log streaming. The snapshot pattern with client cursor is reusable for any streaming log viewer.
Implements TOFU (Trust On First Use) certificate pinning for Signal K WebSocket connections. Supports CA-anchor and leaf-fingerprint modes with a state machine (TofuCaptureDecision). Pure logic, unit-testable, and could be extracted for any IoT project needing secure server identity verification without pre-provisioned certificates.
mDNS-based discovery of Signal K servers on the local network. Uses ESP32's MDNS implementation to resolve _signalk-ws._tcp services. Self-contained networking utility that could be reused in any ESP32 project needing local service discovery.
Frontend request queue with configurable concurrency limit, exponential backoff on failure, and abort signal support. Handles edge cases like clock wraparound and zero timeout. Demonstrates robust async pattern for embedded device APIs where network reliability is low.