|
1 |
| -# Simple Sensor Monitoring System |
| 1 | +# Sensor Monitoring System |
2 | 2 |
|
3 | 3 | ## Overview
|
4 |
| -A lightweight, elegant monitoring system for ESP32 electric ultralight sensors. Based on modern C++ patterns with easy extensibility. |
| 4 | +Real-time health monitoring for ESP32 electric ultralight sensors. Monitors ESC, BMS, altimeter, and system health with threshold-based alerting. |
5 | 5 |
|
6 |
| -## Design Philosophy |
7 |
| -- **Simple**: ~50 lines of core code vs complex alerting systems |
8 |
| -- **Flexible**: Easy to add new sensors and output methods |
9 |
| -- **Modern**: Uses `std::function` and lambdas for clean sensor definitions |
10 |
| -- **Extensible**: Interface-based design for multiple output channels |
| 6 | +## Features |
| 7 | +- **Comprehensive**: 50+ sensors monitored across all flight systems |
| 8 | +- **Smart Alerting**: Hysteresis protection prevents false alerts |
| 9 | +- **Multiple Outputs**: Serial, display, and extensible logging |
| 10 | +- **Efficient**: Minimal overhead, change-only notifications |
11 | 11 |
|
12 |
| -## Usage |
| 12 | +## What's Monitored |
13 | 13 |
|
14 |
| -### Current ESC Temperature Monitoring |
15 |
| -```cpp |
16 |
| -// Automatically monitors: |
17 |
| -// - ESC MOS: Warning 90°C, Critical 110°C |
18 |
| -// - ESC MCU: Warning 80°C, Critical 95°C |
19 |
| -// - ESC CAP: Warning 85°C, Critical 100°C |
20 |
| -// - Motor: Warning 90°C, Critical 110°C |
21 |
| -``` |
| 14 | +### ESC |
| 15 | +- Temperatures (MOS, MCU, CAP, Motor) |
| 16 | +- Error states (over-current, over-temp, voltage issues) |
| 17 | +- Hardware faults and diagnostics |
22 | 18 |
|
23 |
| -### Adding New Sensors |
24 |
| -```cpp |
25 |
| -// Example: Battery voltage monitoring |
26 |
| -static SensorMonitor batteryVoltage = { |
27 |
| - "BatteryVolt", |
28 |
| - {.warnLow = 70, .warnHigh = 105, .critLow = 65, .critHigh = 110}, |
29 |
| - []() { return bmsTelemetryData.battery_voltage; }, |
30 |
| - AlertLevel::OK, |
31 |
| - &serialLogger |
32 |
| -}; |
33 |
| -sensors.push_back(&batteryVoltage); |
34 |
| -``` |
| 19 | +### BMS |
| 20 | +- Cell voltages and temperature sensors |
| 21 | +- State of charge and charge/discharge status |
| 22 | +- Voltage differential monitoring |
35 | 23 |
|
36 |
| -### Example Output |
37 |
| -``` |
38 |
| -[15234] [WARN_HIGH] ESC_MOS_Temp = 92.50 |
39 |
| -[15467] [CRIT_HIGH] Motor_Temp = 112.30 |
40 |
| -[15890] [OK] ESC_MOS_Temp = 88.20 |
41 |
| -``` |
| 24 | +### System |
| 25 | +- CPU temperature and altimeter readings |
| 26 | +- System health and diagnostics |
42 | 27 |
|
43 |
| -## Easy Extensions |
| 28 | +## How It Works |
44 | 29 |
|
45 |
| -### SD Card Logging |
46 |
| -```cpp |
47 |
| -struct SDLogger : ILogger { |
48 |
| - void log(const char* name, AlertLevel lvl, float v) override { |
49 |
| - // Write timestamp, name, level, value to SD card |
50 |
| - File logFile = SD.open("/alerts.log", FILE_APPEND); |
51 |
| - logFile.printf("%lu,%s,%d,%.2f\n", millis(), name, (int)lvl, v); |
52 |
| - logFile.close(); |
53 |
| - } |
54 |
| -}; |
55 |
| -``` |
| 30 | +System automatically monitors all sensors and alerts on threshold violations. Hysteresis prevents false alerts from sensor noise. |
56 | 31 |
|
57 |
| -### Display Alerts |
58 |
| -```cpp |
59 |
| -struct DisplayLogger : ILogger { |
60 |
| - void log(const char* name, AlertLevel lvl, float v) override { |
61 |
| - // Show alert on LVGL display |
62 |
| - if (lvl >= AlertLevel::WARN_HIGH) { |
63 |
| - showAlertPopup(name, lvl, v); |
64 |
| - } |
65 |
| - } |
66 |
| -}; |
67 |
| -``` |
| 32 | +### Alert Levels |
| 33 | +- **OK**: Normal operation |
| 34 | +- **WARN**: Advisory thresholds exceeded |
| 35 | +- **CRIT**: Critical thresholds requiring attention |
68 | 36 |
|
69 |
| -### Multiple Outputs |
70 |
| -```cpp |
71 |
| -// Log to both serial and SD card |
72 |
| -static SerialLogger serialLog; |
73 |
| -static SDLogger sdLog; |
74 |
| - |
75 |
| -sensorMonitor.logger = &serialLog; // Or use both with composite pattern |
| 37 | +### Example Output |
76 | 38 | ```
|
77 |
| - |
78 |
| -## Architecture |
79 |
| - |
80 |
| -```cpp |
81 |
| -ILogger (interface) |
82 |
| -├── SerialLogger (serial console) |
83 |
| -├── SDLogger (SD card - future) |
84 |
| -└── DisplayLogger (LVGL display - future) |
85 |
| - |
86 |
| -SensorMonitor |
87 |
| -├── name (string identifier) |
88 |
| -├── thresholds (warn/crit levels) |
89 |
| -├── read (lambda function) |
90 |
| -└── logger (output interface) |
| 39 | +[15234] [WARN_HIGH] ESC_MOS_Temp = 92.50 |
| 40 | +[15467] [CRIT_HIGH] Motor_Temp = 112.30 |
| 41 | +[15890] [OK] ESC_MOS_Temp = 88.20 |
91 | 42 | ```
|
92 | 43 |
|
93 |
| -## Integration |
94 |
| -- Monitors check every 40ms in main SPI communication task |
95 |
| -- Only logs when alert level changes (no spam) |
96 |
| -- Uses existing telemetry data (no additional sensor reads) |
97 |
| -- Zero overhead when sensors are in OK state |
98 |
| -
|
99 |
| -## Memory Usage |
100 |
| -- ~1KB total code size |
101 |
| -- ~200 bytes per monitored sensor |
102 |
| -- Minimal RAM footprint |
103 |
| -- No dynamic allocation during runtime |
| 44 | +### Integration |
| 45 | +- Runs every 40ms in FreeRTOS task |
| 46 | +- Displays alerts on screen with haptic feedback |
| 47 | +- Serial logging for diagnostics |
| 48 | +- Thread-safe with minimal CPU overhead |
104 | 49 |
|
105 |
| -This approach perfectly balances simplicity with extensibility - start with basic serial logging, easily expand to SD cards, displays, or remote monitoring as needed. |
| 50 | +The system provides comprehensive flight safety monitoring while maintaining performance for electric ultralight operation. |
0 commit comments