monitors industrial signals on ESP32, detects anomalies on-device, and publishes resilient MQTT telemetry.
- Samples
DHT22, gas analog input, andMPU6050vibration. - Runs
FreeRTOStask pipeline with queue-based handoff. - Applies threshold-based alarm logic with latched safety behavior.
- Computes lightweight anomaly score (
0.0-1.0) and anomaly source. - Publishes JSON telemetry over MQTT with offline queue + retry.
- Persists runtime thresholds to ESP32
NVS. - Exposes operator controls via UART console.
sensor_task -> processing_task -> control_task -> shared runtime
| |
| +-> telemetry_task (MQTT)
+-> anomaly detector +-> console_task (UART)
supervisor_task monitors heartbeats of all tasks and forces FAULT on stalls.
src/main.cpp: task wiring, runtime orchestration, supervisor.src/alarm_logic.cpp: threshold and latched alarm state machine.src/anomaly_detector.cpp: adaptive baseline + variance anomaly scoring.src/mqtt_telemetry.cpp: WiFi/MQTT client with retry and offline buffering.src/config_persistence_esp32.cpp: threshold save/load with NVS.test/test_core.cpp: host-runnable tests for core logic.
- Install PlatformIO:
brew install platformio- Build firmware:
pio run -e esp32dev- Run Wokwi simulation (uses
diagram.jsonandwokwi.toml), then open serial monitor at115200.
help
status
thresholds
reset_alarm
set temp_warn 36
set temp_alarm 44
set hum_warn 72
set hum_alarm 85
set vib_warn 0.18
set vib_alarm 0.35
set gas_warn 1900
set gas_alarm 2900
set safe_ms 10000
- Broker:
broker.hivemq.com:1883 - Topic:
karimFin/esp32-edge-monitor-firmware/telemetry - Includes: sensor averages, state, fault info,
anomaly_score,anomaly_src - Reliability: bounded offline queue + reconnect flush
- Optional security flags in
platformio.ini:MQTT_USE_TLS,MQTT_USERNAME,MQTT_PASSWORD
- Start in
NORMALwith stable sensor values. - Increase gas/vibration to trigger
WARNINGandALARM. - Observe anomaly score rising before or during threshold transitions.
- Use UART
setcommands to tune thresholds live. - Disconnect/reconnect network and confirm queued telemetry flushes.
- Reboot and verify threshold settings reload from NVS.
mkdir -p build
clang++ -std=c++17 -Iinclude test/test_core.cpp src/alarm_logic.cpp src/anomaly_detector.cpp src/console_parser.cpp src/mpu6050_driver.cpp src/telemetry_utils.cpp -o build/test_core
./build/test_core- GitHub Actions runs on push/PR:
- host unit tests
pio run -e esp32dev
