feat: semver versioning, FastAPI OTA integration, health alerts via MQTT

- Version.hpp: extract FW_VERSION from main.cpp into shared header
- OTAManager: replace uint16_t version with SemVer struct; update API URLs
  to new FastAPI backend (/api/firmware/{hw_type}/{channel}/latest);
  add postDownloadTelemetry() and postFlashTelemetry() for fleet visibility
- ConfigManager: remove fwVersion from DeviceConfig (always read from
  FW_VERSION constant); saveDeviceConfig/loadDeviceConfig are now no-ops;
  fallbackServerUrl replaced with fallbackServerUrls[2] array
- HealthMonitor: add AlertCallback + setAlertCallback() firing on state
  transitions (including CLEARED on recovery)
- CommunicationRouter: wire HealthMonitor alert callback on begin();
  add publishAlert() and publishInfo() for MQTT status topics
- MQTTDriver: add _alertsTopic + _infoTopic; add publishDirect() for
  absolute topic publishing; migrate heartbeat to JsonDocument
- ResponseBuilder, ClientManager, BellEngine: StaticJsonDocument /
  DynamicJsonDocument → JsonDocument; remove dead notifyBellsFired()
- docs: reorganise into architecture/, dev/, features/, reference/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-14 22:15:27 +02:00
co-authored by Claude Sonnet 4.6
parent c3dc0a79bc
commit d4bd990e53
33 changed files with 1874 additions and 301 deletions
@@ -76,10 +76,14 @@ void MQTTDriver::begin() {
// Build topic strings (cache for performance)
String deviceUID = _configManager.getDeviceUID();
_controlTopic = "vesper/" + deviceUID + "/control";
_dataTopic = "vesper/" + deviceUID + "/data";
_clientId = "vesper-" + deviceUID;
LOG_INFO(TAG, "MQTT Topics: control=%s, data=%s", _controlTopic.c_str(), _dataTopic.c_str());
_dataTopic = "vesper/" + deviceUID + "/data";
_alertsTopic = "vesper/" + deviceUID + "/status/alerts";
_infoTopic = "vesper/" + deviceUID + "/status/info";
_clientId = "vesper-" + deviceUID;
LOG_INFO(TAG, "MQTT Topics: control=%s, data=%s, alerts=%s, info=%s",
_controlTopic.c_str(), _dataTopic.c_str(),
_alertsTopic.c_str(), _infoTopic.c_str());
// Setup event handlers
_mqttClient.onConnect([this](bool sessionPresent) {
@@ -165,6 +169,17 @@ uint16_t MQTTDriver::publish(const String& topic, const String& payload, int qos
return packetId;
}
uint16_t MQTTDriver::publishDirect(const String& fullTopic, const String& payload, int qos, bool retain) {
if (!_mqttClient.connected()) {
return 0;
}
uint16_t packetId = _mqttClient.publish(fullTopic.c_str(), qos, retain, payload.c_str());
if (packetId > 0) {
LOG_DEBUG(TAG, "Published to %s (packetId=%d)", fullTopic.c_str(), packetId);
}
return packetId;
}
void MQTTDriver::setCallback(MessageCallback callback) {
_messageCallback = callback;
}
@@ -361,11 +376,11 @@ void MQTTDriver::publishHeartbeat() {
}
// Build heartbeat JSON message
StaticJsonDocument<512> doc;
JsonDocument doc;
doc["status"] = "INFO";
doc["type"] = "heartbeat";
JsonObject payload = doc.createNestedObject("payload");
JsonObject payload = doc["payload"].to<JsonObject>();
// Device ID from NVS
payload["device_id"] = _configManager.getDeviceUID();
@@ -49,6 +49,7 @@ public:
/**
* @brief Publish message to MQTT
* @param topic Topic to publish to (relative, will prepend "vesper/{deviceID}/")
* If empty string — publishes to the data topic.
* @param payload Message payload
* @param qos QoS level (0, 1, or 2)
* @param retain Retain flag
@@ -56,6 +57,16 @@ public:
*/
uint16_t publish(const String& topic, const String& payload, int qos = 0, bool retain = false);
/**
* @brief Publish to an absolute, fully-qualified topic (no prefix applied).
* @param fullTopic Complete topic string
* @param payload Message payload
* @param qos QoS level (0, 1, or 2)
* @param retain Retain flag
* @return Packet ID (0 if failed)
*/
uint16_t publishDirect(const String& fullTopic, const String& payload, int qos = 0, bool retain = false);
/**
* @brief Set message received callback
*/
@@ -66,6 +77,10 @@ public:
*/
bool isConnected() const;
/** @brief Full topic strings (read-only, available after begin()) */
const String& getAlertsTopic() const { return _alertsTopic; }
const String& getInfoTopic() const { return _infoTopic; }
/**
* @brief Handle network connection callback
*/
@@ -86,7 +101,9 @@ private:
// Device topic strings (cached for performance)
String _controlTopic;
String _dataTopic;
String _clientId; // Store client ID to keep it alive
String _alertsTopic; // vesper/{id}/status/alerts
String _infoTopic; // vesper/{id}/status/info
String _clientId; // Store client ID to keep it alive
/**
* @brief Subscribe to control topic
@@ -98,7 +98,7 @@ void UARTDriver::processLine(const char* line) {
if (strlen(line) == 0) return;
// Parse JSON
StaticJsonDocument<1024> doc;
JsonDocument doc;
DeserializationError error = deserializeJson(doc, line);
if (error) {
@@ -106,7 +106,7 @@ void UARTDriver::processLine(const char* line) {
_errorCount++;
// Send error response back
StaticJsonDocument<256> errorDoc;
JsonDocument errorDoc;
errorDoc["status"] = "ERROR";
errorDoc["type"] = "parse_error";
errorDoc["payload"] = error.c_str();
@@ -132,7 +132,7 @@ void WebSocketDriver::onData(AsyncWebSocketClient* client, void* arg, uint8_t* d
LOG_DEBUG(TAG, "WebSocket client #%u sent: %s", client->id(), payload);
// Parse JSON
StaticJsonDocument<2048> doc;
JsonDocument doc;
DeserializationError error = deserializeJson(doc, payload);
if (error) {