Tau.Acuvim/firmware/include/health_monitor.h
Renier Forster 84a0668c54 Initial commit: Tau Acuvim IoT monitoring system
Complete IoT monitoring platform for Acuvim II power meters via ESP32.

Firmware (Phases 1-7):
- ESP32-WROVER-B (TTGO T-Call v1.4) with RS485 Modbus RTU
- WiFi STA+AP concurrent mode with GSM/GPRS failover
- Transport abstraction layer with 4 priority modes
- MQTT protocol with 20 commands, LWT, QoS, exponential backoff
- SD card offline buffering with JSONL rotation and non-blocking drain
- OTA firmware updates with dual partition rollback protection
- Watchdog timer, crash loop detection, Acuvim health monitoring
- Captive portal provisioning with AP mode

Console backend (Phase 8):
- .NET 10 minimal API with PostgreSQL + EF Core
- JWT authentication, SignalR real-time updates
- MQTTnet 5.x bridge service with health monitoring
- Device, telemetry, firmware, alert, group management
- Rate limiting, security headers, Swagger/OpenAPI

Frontend (Phase 9):
- React 18 + TypeScript + Vite with Ant Design 5
- ECharts telemetry visualization, TanStack Query
- SignalR live updates, device management UI
- Dashboard, fleet management, firmware deployment

Testing & Production (Phase 10):
- 28 firmware unit tests (Modbus, JSON, config, version)
- 23 xUnit backend tests (device, telemetry, command, alert)
- Docker Compose with nginx, TLS MQTT, PostgreSQL
- Production deployment, commissioning, and troubleshooting docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-16 19:05:32 +02:00

66 lines
1.7 KiB
C++

#ifndef HEALTH_MONITOR_H
#define HEALTH_MONITOR_H
#include <Arduino.h>
#include "config_manager.h"
#include "mqtt_client.h"
#include "acuvim_reader.h"
#include "acuvim_registers.h"
struct AlertThresholds {
float overvoltage;
float undervoltage;
float overcurrent;
float voltage_imbalance_pct;
float current_imbalance_pct;
float freq_low;
float freq_high;
float low_pf;
float high_thd;
uint8_t modbus_consecutive_errors;
float modbus_error_rate_pct;
};
class HealthMonitor {
public:
void begin(ConfigManager& config, MqttClient& mqtt, AcuvimReader& acuvim);
void evaluate(const AcuvimData& data);
void setThresholds(const AlertThresholds& t) { _thresholds = t; }
const AlertThresholds& getThresholds() const { return _thresholds; }
private:
ConfigManager* _config;
MqttClient* _mqtt;
AcuvimReader* _acuvim;
AlertThresholds _thresholds;
// Active alert flags for deduplication
bool _alertOvervoltageA;
bool _alertOvervoltageB;
bool _alertOvervoltageC;
bool _alertUndervoltageA;
bool _alertUndervoltageB;
bool _alertUndervoltageC;
bool _alertOvercurrentA;
bool _alertOvercurrentB;
bool _alertOvercurrentC;
bool _alertVoltageImbalance;
bool _alertCurrentImbalance;
bool _alertFreqDeviation;
bool _alertLowPF;
bool _alertHighTHD;
bool _alertModbusLoss;
bool _alertModbusErrorRate;
void publishAlert(const char* alert, const char* severity,
const String& message, float value, float threshold,
const char* phase = nullptr);
void checkVoltage(float value, const char* phase, bool& overFlag, bool& underFlag);
void checkCurrent(float value, const char* phase, bool& flag);
};
#endif