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:
@@ -0,0 +1,209 @@
|
||||
# Vesper — MQTT Events Reference
|
||||
|
||||
> Source of truth for all unsolicited MQTT messages published by Vesper firmware.
|
||||
> Use this document to generate or update the AsyncAPI specification in the backend console.
|
||||
> Last updated: 2026-03-01
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Vesper publishes on four MQTT topics. All topics are device-scoped under the prefix `vesper/{device_id}/`.
|
||||
|
||||
| Topic | Direction | QoS | Retained | Purpose |
|
||||
|-------|-----------|-----|----------|---------|
|
||||
| `vesper/{id}/control` | Inbound | — | — | Commands from server/app |
|
||||
| `vesper/{id}/data` | Outbound | 0 | no | Command responses + bell overload events |
|
||||
| `vesper/{id}/status/heartbeat` | Outbound | 1 | yes | Periodic liveness signal |
|
||||
| `vesper/{id}/status/alerts` | Outbound | 1 | no | Subsystem state-change events |
|
||||
| `vesper/{id}/status/info` | Outbound | 0 | no | General device state events |
|
||||
|
||||
Subscribe to `vesper/+/status/#` to receive all status events from all devices.
|
||||
|
||||
---
|
||||
|
||||
## `vesper/{id}/status/heartbeat`
|
||||
|
||||
**QoS:** 1 — **Retained:** yes — **Interval:** 30 seconds
|
||||
|
||||
Published immediately on MQTT connect, then every 30 seconds. The broker retains the last message so any new subscriber instantly sees whether the device is alive.
|
||||
|
||||
The server should:
|
||||
- Update `last_seen` timestamp silently — **no log entry, no display update**
|
||||
- Raise an offline alert if no heartbeat is received within 90 seconds (3 missed beats)
|
||||
|
||||
### Payload
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "INFO",
|
||||
"type": "heartbeat",
|
||||
"payload": {
|
||||
"device_id": "PV-26B18-VS01R-X7KQA",
|
||||
"firmware_version": "154",
|
||||
"timestamp": "Uptime: 5h 23m 45s",
|
||||
"ip_address": "10.0.0.3",
|
||||
"gateway": "10.0.0.1",
|
||||
"uptime_ms": 19425000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `payload.device_id` | string | Device serial number (from NVS) |
|
||||
| `payload.firmware_version` | string | Firmware build version string |
|
||||
| `payload.timestamp` | string | Human-readable uptime string |
|
||||
| `payload.ip_address` | string | Current device IP |
|
||||
| `payload.gateway` | string | Network gateway IP |
|
||||
| `payload.uptime_ms` | integer | Milliseconds since boot |
|
||||
|
||||
---
|
||||
|
||||
## `vesper/{id}/status/alerts`
|
||||
|
||||
**QoS:** 1 — **Retained:** no — **Trigger:** subsystem state change only
|
||||
|
||||
Published by `HealthMonitor` (via `CommunicationRouter::publishAlert()`) whenever a subsystem transitions between health states. Published once on change; not repeated until the state changes again. Silent if MQTT is not connected at the moment of the transition.
|
||||
|
||||
The server should:
|
||||
- Maintain a **per-device active alert set** (e.g. a dict keyed by `subsystem`)
|
||||
- On receipt: upsert the alert in the set
|
||||
- On `CLEARED`: remove the entry from the set
|
||||
- Display the active alert set statically on the device detail page — **not as a scrolling log**
|
||||
|
||||
### Alert payload (problem)
|
||||
|
||||
```json
|
||||
{
|
||||
"subsystem": "FileManager",
|
||||
"state": "WARNING",
|
||||
"msg": "ConfigManager health check failed"
|
||||
}
|
||||
```
|
||||
|
||||
### Cleared payload (recovery)
|
||||
|
||||
```json
|
||||
{
|
||||
"subsystem": "FileManager",
|
||||
"state": "CLEARED"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `subsystem` | string | Subsystem name. One of: `BellEngine`, `OutputManager`, `Player`, `Communication`, `TimeKeeper`, `Telemetry`, `OTAManager`, `Networking`, `ConfigManager`, `FileManager` |
|
||||
| `state` | string | New state: `WARNING` \| `CRITICAL` \| `FAILED` \| `CLEARED` |
|
||||
| `msg` | string | Human-readable description. Absent when `state` is `CLEARED`. |
|
||||
|
||||
### State meanings
|
||||
|
||||
| State | Meaning |
|
||||
|-------|---------|
|
||||
| `WARNING` | Subsystem has an issue but device continues to operate |
|
||||
| `CRITICAL` | Subsystem failure affects core functionality |
|
||||
| `FAILED` | Subsystem is non-functional (equivalent to CRITICAL for critical subsystems) |
|
||||
| `CLEARED` | Subsystem has recovered; remove from active alert set |
|
||||
|
||||
### Critical vs non-critical subsystems
|
||||
|
||||
| Subsystem | Critical? | Notes |
|
||||
|-----------|-----------|-------|
|
||||
| BellEngine | yes | Core timing — CRITICAL triggers rollback consideration |
|
||||
| OutputManager | yes | Hardware — CRITICAL triggers rollback consideration |
|
||||
| Player | yes | Melody control |
|
||||
| ConfigManager | no | SD card absence maps to WARNING |
|
||||
| FileManager | no | SD card absence maps to WARNING |
|
||||
| Communication | no | MQTT/WS failure |
|
||||
| TimeKeeper | no | RTC sync failure |
|
||||
| Telemetry | no | Strike counting |
|
||||
| OTAManager | no | OTA update subsystem |
|
||||
| Networking | no | WiFi connectivity |
|
||||
|
||||
---
|
||||
|
||||
## `vesper/{id}/status/info`
|
||||
|
||||
**QoS:** 0 — **Retained:** no — **Trigger:** significant device state change
|
||||
|
||||
Published for general device state changes that are not health failures. Use this topic to update the device detail panel (e.g. current playback, reboot reason) without polling.
|
||||
|
||||
The server should display the most recent `info` payload for each event `type` on the device detail page.
|
||||
|
||||
### Envelope
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "event_type",
|
||||
"payload": { ... }
|
||||
}
|
||||
```
|
||||
|
||||
### Event types (current and planned)
|
||||
|
||||
| `type` | When | Payload fields |
|
||||
|--------|------|----------------|
|
||||
| `playback_started` | Player begins playing a melody | `melody_uid` (string) |
|
||||
| `playback_stopped` | Player stops | *(none)* |
|
||||
|
||||
> **Note:** `publishInfo()` exists in `CommunicationRouter` but is not yet called from any subsystem. Call sites will be added as feature work in subsequent firmware versions. The API is stable.
|
||||
|
||||
---
|
||||
|
||||
## `vesper/{id}/data`
|
||||
|
||||
**QoS:** 0 — **Retained:** no
|
||||
|
||||
Published in response to commands and for unsolicited events that are not health-related.
|
||||
|
||||
### Command response envelope
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS" | "ERROR",
|
||||
"type": "command_name",
|
||||
"payload": { ... }
|
||||
}
|
||||
```
|
||||
|
||||
### Bell overload event
|
||||
|
||||
Published by `CommunicationRouter::sendBellOverloadNotification()` when per-bell strike load exceeds configured thresholds.
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "INFO",
|
||||
"type": "bell_overload",
|
||||
"payload": {
|
||||
"bells": [2, 5],
|
||||
"loads": [54, 48],
|
||||
"severity": "WARNING"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `payload.bells` | array of int | 1-indexed bell channel numbers that are overloaded |
|
||||
| `payload.loads` | array of int | Strike count load per bell channel |
|
||||
| `payload.severity` | string | `WARNING` (≥60% load) or `CRITICAL` (≥90% load) |
|
||||
|
||||
---
|
||||
|
||||
## Server subscription pattern
|
||||
|
||||
```
|
||||
vesper/+/status/heartbeat → update last_seen, no logging
|
||||
vesper/+/status/alerts → upsert/remove active alert set per device
|
||||
vesper/+/status/info → update device state panel
|
||||
vesper/+/data → display command responses, handle bell_overload
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Removed events
|
||||
|
||||
| Event | Was published to | Removed in | Reason |
|
||||
|-------|-----------------|------------|--------|
|
||||
| `ding` (bell fired) | `vesper/{id}/data` (WebSocket only) | Firmware v155+ | Unstable under load; no active consumers |
|
||||
Reference in New Issue
Block a user