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>
86 lines
1.5 KiB
C++
86 lines
1.5 KiB
C++
#ifndef CONFIG_MANAGER_H
|
|
#define CONFIG_MANAGER_H
|
|
|
|
#include <Arduino.h>
|
|
#include <ArduinoJson.h>
|
|
|
|
#define NVS_NAMESPACE "acuvim_cfg"
|
|
|
|
struct DeviceConfig {
|
|
char device_id[32];
|
|
|
|
// WiFi
|
|
char wifi_ssid[64];
|
|
char wifi_password[64];
|
|
bool wifi_enabled;
|
|
|
|
// MQTT
|
|
char mqtt_broker[128];
|
|
uint16_t mqtt_port;
|
|
char mqtt_username[64];
|
|
char mqtt_password[64];
|
|
char mqtt_topic_prefix[64];
|
|
bool mqtt_tls;
|
|
|
|
// GSM
|
|
char gsm_apn[64];
|
|
char gsm_user[32];
|
|
char gsm_pass[32];
|
|
bool gsm_enabled;
|
|
|
|
// Transport
|
|
uint8_t transport_priority;
|
|
uint16_t gsm_poll_interval_sec;
|
|
bool gsm_batch_enabled;
|
|
uint8_t gsm_batch_size;
|
|
|
|
// SD Card
|
|
uint16_t sd_retention_days;
|
|
|
|
// Console
|
|
char console_url[128];
|
|
|
|
// Acuvim II / Modbus
|
|
uint8_t modbus_slave_addr;
|
|
uint32_t modbus_baud_rate;
|
|
uint16_t poll_interval_sec;
|
|
|
|
// Sleep
|
|
uint16_t sleep_duration_min;
|
|
uint16_t wake_duration_sec;
|
|
|
|
// Heartbeat
|
|
uint16_t heartbeat_interval_sec;
|
|
|
|
// OTA
|
|
uint8_t ota_check_interval_hours;
|
|
uint8_t ota_auto_update;
|
|
|
|
// Firmware
|
|
char firmware_version[16];
|
|
};
|
|
|
|
class ConfigManager {
|
|
public:
|
|
void begin();
|
|
void save();
|
|
void reset();
|
|
|
|
DeviceConfig& get() { return _config; }
|
|
const DeviceConfig& get() const { return _config; }
|
|
|
|
String toJson(bool includeSecrets = false);
|
|
bool fromJson(const String& json);
|
|
|
|
String getDeviceId();
|
|
|
|
private:
|
|
DeviceConfig _config;
|
|
|
|
void loadDefaults();
|
|
void loadFromNVS();
|
|
void generateDeviceId();
|
|
};
|
|
|
|
#endif
|