How angelointj/simut works
1. Purpose and Runtime
SIMUT is offline-capable IoT firmware for Raspberry Pi Pico W/RP2040, built on Arduino-Pico through PlatformIO. It monitors up to 16 configurable temperature/humidity/pressure sensor slots, presents local TFT/touch and embedded-web interfaces, retains audit/history data in flash, and exports telemetry.
Primary firmware entry point: src/main.cpp. Build/environment and partition behavior are defined in platformio.ini; deployment can run in Docker via Dockerfile and docker-compose.yml.
2. Application Orchestration and Dual-Core Boundary
AppManager is the central lifecycle/state coordinator: boot, periodic main-loop work, sensor processing, commands, events, graphs, and historical alarms are split across src/AppManager_Boot.cpp, src/AppManager_Loop.cpp, and src/AppManager_Sensors.cpp (with interface in src/AppManager.h).
Core 0 runs application, networking, storage, telemetry, and CLI work. Core 1 owns display/touch work. Cross-core communication is via application state/snapshots; flash operations require Core 1 pausing, with concurrency checking support in src/ConcurrencyAsserts.h and src/FlashIrqProbe.cpp.
3. Acquisition, Alarm, and Persistence Pipeline
SensorManager discovers/configures and samples DS18B20, DHT22, and BMx280 devices, converting readings into first-class channels and applying calibration/error handling. Core paths: src/SensorManager.cpp, src/SensorManager.h, src/sensors/SensorChannels.h.
Sensor results flow through application alarm evaluation and queueing (src/AlarmQueue.h, src/AlarmPayload.h), then into current state, UI/web snapshots, telemetry, and historical persistence.
StorageManager owns LittleFS access, durable configuration, and file lifecycle (src/StorageManager.cpp, src/StorageManager.h). Binary V5 history is a separate codec/store layer in src/HistoryV5.cpp and src/HistoryV5.h, using daily records for later graphing/export. This flash boundary is critical for watchdog and dual-core safety.
4. Local Display and Interaction
DisplayManager is Core 1’s UI controller, responsible for dashboard, graphs, calibration, settings, authentication screens, touch dispatch, fonts, themes, and language-pack loading. Main boundaries: src/DisplayManager.cpp, src/DisplayManager_Touch.cpp, src/DisplayManager_Graph.cpp.
Display hardware abstractions select TFT/LCD and touch drivers through src/display/DisplayDriver.h, src/display/ILI9341_320x240.h, and src/display/XPT2046.h. Themes and persisted theme assets are represented by src/Themes.cpp and data/themes/; external PT/ES language packs reside in data/lang/.
5. Network, Web, and Authorization Surface
NetworkManager establishes Wi-Fi, mDNS, NTP, and setup-AP behavior (src/NetworkManager.cpp, src/NetworkManager.h). WebManager exposes embedded UI, REST API, history/downloads, file operations, metrics, calibration, and OTA routes through src/WebManager_Core.cpp, src/WebManager_Api.cpp, and src/WebManager_Auth.cpp.
The browser UI is bundled in WebUI.h. History is intentionally served as raw binary files; browser-side code handles graph bucketing and CSV conversion. Web authorization/session enforcement is a boundary ahead of mutable configuration, filesystem, OTA, and administrative endpoints.
6. External Integrations and Operations
TelemetryManager batches readings for HTTP POST or MQTT, including optional Home Assistant discovery (src/TelemetryManager.cpp, src/TelemetryManager.h, src/HaDiscovery.h). Prometheus exposition is handled by src/WebManager_Metrics.cpp and src/PromMetrics.h; remote RFC 5424 UDP logging uses src/SyslogManager.cpp.
LogManager and policy filtering provide local diagnostics/crash-forensics persistence (src/LogManager.cpp, src/LogPolicy.cpp). USB CDC CLI enters through command parsing/dispatch in src/CommandManager.cpp and src/CommandParser.cpp.
7. Update and Recovery Subsystem
OTA is a staged workflow separated from web transport: web routes accept uploads, while src/ota/orchestrator.cpp coordinates validation, firmware staging/application, configuration snapshots, and backup/restore. Key stages are src/ota/validation.cpp, src/ota/firmware_stage.cpp, and src/ota/restore.cpp.
This isolation preserves Wi-Fi/users/sensor configuration across firmware replacement and protects flash integrity through metadata, CRC-oriented backup formats, and controlled apply/rollback-related steps.
Main entry points: AppManager.h AppManager · WebManager_Core.cpp WebManager · StorageManager.cpp StorageManager · DisplayManager.cpp DisplayManager
Components 19
Core 0 services
Application, network, storage, and integrations.
- AppManager · Coordinates boot, loop, state, alarms, and snapshots.
src/AppManager.h - SensorManager · Discovers and samples configured sensor slots.
src/SensorManager.cpp - Sensor channels
src/sensors/SensorChannels.h - Alarm queue
src/AlarmQueue.h - StorageManager · Owns durable configuration and file lifecycle.
src/StorageManager.cpp - V5 history store · Persists historical readings for graphs and export.
src/HistoryV5.cpp - NetworkManager · Manages Wi-Fi, mDNS, NTP, and setup AP.
src/NetworkManager.cpp - WebManager · Serves UI, API, downloads, files, metrics, and OTA routes.
src/WebManager_Core.cpp - Web authorization · Guards mutable and administrative routes.
src/WebManager_Auth.cpp - TelemetryManager
src/TelemetryManager.cpp - Diagnostics logging
src/LogManager.cpp - USB CDC CLI
src/CommandManager.cpp - OTA orchestrator · Validates, stages, applies, and restores firmware updates.
src/ota/orchestrator.cpp - Flash safety checks · Coordinates Core 1 pause during flash operations.
src/ConcurrencyAsserts.h
Core 1 UI
Display and touch runtime.
- DisplayManager · Owns dashboard, graphs, settings, screens, and touch dispatch.
src/DisplayManager.cpp - TFT and touch drivers
src/display/DisplayDriver.h
Local and remote surfaces
- Browser UI · Graphs raw history and converts it to CSV client-side.
WebUI.h - Remote consumers · HTTP/MQTT, Home Assistant, and UDP syslog targets.
src/HaDiscovery.h
Other components
- Firmware entry
src/main.cpp
Connections 22
- Firmware entry → AppManager: boots
- AppManager → SensorManager: samples
- SensorManager → Sensor channels: produces
- Sensor channels → Alarm queue: evaluates
- AppManager → StorageManager: loads and saves state
- Alarm queue → V5 history store: persists records
- StorageManager → V5 history store: LittleFS access
- AppManager → NetworkManager: starts
- NetworkManager → WebManager: connectivity
- Web authorization → WebManager: protects routes
- WebManager → Browser UI: serves UI and API
- WebManager → V5 history store: serves raw files
- AppManager → TelemetryManager: provides readings
- TelemetryManager → Remote consumers: exports
- Diagnostics logging → Remote consumers: forwards syslog
- USB CDC CLI → AppManager: commands
- WebManager → OTA orchestrator: upload transport
- OTA orchestrator → StorageManager: backup and restore
- AppManager → DisplayManager: state snapshots · Cross-core communication boundary.
- DisplayManager → TFT and touch drivers: renders and reads touch
- Flash safety checks → StorageManager: guards flash operations
- Flash safety checks → DisplayManager: pauses Core 1