feat(MQTT): rebuild topic spec to v2 (F-062)

Full MQTT topic rebuild per docs/reference/vesper_mqtt_topic_spec_v2.md.
Only the MQTT transport path changed — WebSocket, HTTP, and UART are untouched.

- control/command (in) + control/ack (out, strictly replies) replace the old
  control/data pair; new control/reports for critical unsolicited events
  (bell overload) that don't belong on the strictly-reply ack channel
- status/playback split out for playback transitions only
- status/alerts + status/info renamed to system/alerts + system/info, both
  now correctly retained; new system/logs and system/metrics (diagnostics
  report moved here from system/info, gained bell strike/heat data)
- LWT registered for the first time — status/heartbeat gets
  {"state":"offline","ok":false} on an unclean disconnect; graceful
  disconnect (mqtt.disable) announces offline explicitly since LWT doesn't
  fire on a clean disconnect
- heartbeat payload flattened, gains independently-derived state/ok fields
  (via a new MQTTDriver::setStateProvider() wired from Player+HealthMonitor)
- optional req_id correlation added bus-wide (CommandEnvelope/CommandResult),
  not MQTT-only, since any transport with multiple senders sharing one
  channel has the same problem. Always optional — v1 clients unaffected.
- per-topic ON/OFF switches (ConfigManager::MqttTopicConfig, 8 flags) as
  sub-switches under the existing mqtt.enable/disable master switch, so a
  device can breathe by disabling topics it doesn't need. New
  mqtt.get_topics/mqtt.set_topics commands; command switch applies live.

Bumped to v2.2.0. Verified: pio run -e vesper-std-v1 -e agnus-v1 both build clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 10:48:36 +03:00
co-authored by Claude Sonnet 5
parent 20576f12ff
commit 391ecb63fc
26 changed files with 1053 additions and 330 deletions
+68 -66
View File
@@ -2,7 +2,7 @@
> Command reference for the Vesper Bell Automation System.
> Firmware v2 command bus architecture — all transports, all handlers.
> Last updated: 2026-03-16
> Last updated: 2026-09-21 (MQTT topic spec v2 — see F-062 in feature-catalog.md)
---
@@ -16,6 +16,7 @@ Every command sent to Vesper uses this JSON envelope:
{
"v": 2,
"cmd": "namespace.command",
"req_id": "abc123",
"contents": { ... }
}
```
@@ -24,6 +25,7 @@ Every command sent to Vesper uses this JSON envelope:
|---|---|---|
| `v` | int | Protocol version. `2` = current. Omit or set `1` for legacy (LegacyAdapter runs). |
| `cmd` | string | `namespace.command` format (e.g. `relay.set_durations`). |
| `req_id` | string | Optional. Echoed back on the reply for correlation when a caller shares one channel across multiple requests/senders (e.g. MQTT `control/command`). Omit for a reply with no `req_id` field — fully backward compatible. |
| `contents` | object | Command payload. May be omitted if command takes no fields. |
### Response Envelope
@@ -32,23 +34,30 @@ Every command sent to Vesper uses this JSON envelope:
{
"status": "SUCCESS" | "ERROR",
"type": "command_name",
"req_id": "abc123",
"payload": { ... }
}
```
`payload` is command-specific. On error, `payload` typically contains a `"message"` string.
`payload` is command-specific. On error, `payload` typically contains a `"message"` string. `req_id` is present only if the request included one.
---
## Transports
MQTT uses the v2 topic set — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md) for the full table, per-topic ON/OFF switches, `req_id` correlation, and LWT. WebSocket, HTTP, and UART are unchanged by the v2 MQTT rebuild.
| Transport | Address | Direction | Notes |
|---|---|---|---|
| MQTT | `vesper/{device_id}/control` | Inbound commands | Responses go to `vesper/{device_id}/data` |
| MQTT | `vesper/{device_id}/data` | Outbound responses + events | Command replies and bell overload notifications |
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s; server updates last_seen |
| MQTT | `vesper/{device_id}/status/alerts` | Outbound, QoS 1 | Subsystem state-change events (published on change only) |
| MQTT | `vesper/{device_id}/status/info` | Outbound, QoS 0 | General device state events (playback, reboot reason, etc.) |
| MQTT | `vesper/{device_id}/control/command` | Inbound commands | Read-only from the board's perspective. Replies go to `control/ack`. |
| MQTT | `vesper/{device_id}/control/ack` | Outbound replies | Strictly request/response — nothing unsolicited |
| MQTT | `vesper/{device_id}/control/reports` | Outbound, critical unsolicited events | e.g. bell overload — not retained |
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s + LWT; server updates last_seen |
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 1 | Playback transitions only |
| MQTT | `vesper/{device_id}/system/alerts` | Outbound, retained until cleared, QoS 1 | Subsystem state-change events (published on change only) |
| MQTT | `vesper/{device_id}/system/info` | Outbound, retained, QoS 1 | Discrete device state events (boot report, etc.) |
| MQTT | `vesper/{device_id}/system/logs` | Outbound, QoS 0 | Mirrors serial log stream |
| MQTT | `vesper/{device_id}/system/metrics` | Outbound, QoS 0 | Structured telemetry every 5 min — fleet-health graphing |
| WebSocket | `ws://{device_ip}/ws` | Bidirectional | Requires `identify` on connect |
| HTTP | `http://{device_ip}/...` | REST | Web console endpoints |
| UART | Hardware serial | Bidirectional | Restricted — whitelist only (see below) |
@@ -913,13 +922,54 @@ Enable or disable RF reception at runtime.
### `mqtt.enable` / `mqtt.disable`
Enable or disable MQTT connectivity.
Enable or disable MQTT connectivity (master switch — disconnects/reconnects the broker entirely). `mqtt.disable` publishes a graceful offline heartbeat before disconnecting.
```json
{ "v": 2, "cmd": "mqtt.enable" }
{ "v": 2, "cmd": "mqtt.disable" }
```
### `mqtt.get_config`
Returns broker connection settings.
| | |
|---|---|
| Returns | `{ "enabled": true, "host": "72.61.191.197", "port": 1883, "user": "...", "use_ssl": false }` |
```json
{ "v": 2, "cmd": "mqtt.get_config" }
```
### `mqtt.get_topics`
Returns the current state of all 8 per-topic ON/OFF publish switches. See [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md#per-topic-onoff-switches).
| | |
|---|---|
| Returns | `{ "command": true, "heartbeat": true, "playback": true, "reports": true, "alerts": true, "info": true, "logs": true, "metrics": true }` |
```json
{ "v": 2, "cmd": "mqtt.get_topics" }
```
### `mqtt.set_topics`
Partial update of the per-topic ON/OFF switches — only send the fields you want to change. These only take effect while `mqtt.enable` (the master switch) is on. `command` gates both `control/command` (subscription) and `control/ack` (replies) together, and applies live without a reconnect.
| | |
|---|---|
| Optional | Any of `command`, `heartbeat`, `playback`, `reports`, `alerts`, `info`, `logs`, `metrics` (bool) — at least one required |
```json
{ "v": 2, "cmd": "mqtt.set_topics", "contents": { "heartbeat": true, "metrics": false } }
```
| Error | Condition |
|---|---|
| `"No recognised topic fields in contents (command, heartbeat, playback, reports, alerts, info, logs, metrics)"` | No valid boolean fields present |
| `"Topic switches changed but failed to save to SD"` | Applied in RAM but persistence failed |
---
## Telemetry Namespace — `TelemetryHandler`
@@ -971,66 +1021,18 @@ Get heat load per bell channel, cooling status, and overload flags.
## MQTT Events (Unsolicited)
These messages are published by the device without a request. See [mqtt-events.md](mqtt-events.md) for the full AsyncAPI-compatible reference.
These messages are published by the device without a request, on the v2 topic set (`control/command`+`control/ack`, `control/reports`, `status/heartbeat`, `status/playback`, `system/alerts`, `system/info`, `system/logs`, `system/metrics`). Full field-level reference, per-topic switches, LWT, and `req_id` correlation: [mqtt-events.md](mqtt-events.md) and [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md).
| Topic | When | QoS | Retained | Format |
| Topic | When | QoS | Retained | Switch |
|---|---|---|---|---|
| `vesper/{id}/status/heartbeat` | Every 30s | 1 | yes | Heartbeat envelope |
| `vesper/{id}/status/alerts` | On subsystem state change only | 1 | no | Alert envelope |
| `vesper/{id}/status/info` | On device state change | 0 | no | Info envelope |
| `vesper/{id}/data` | Any command response / bell overload | 0 | no | Standard response envelope |
### Heartbeat Payload
```json
{
"status": "INFO",
"type": "heartbeat",
"payload": {
"device_id": "PV-26B18-VS01R-X7KQA",
"firmware_version": "142",
"timestamp": "Uptime: 5h 23m 45s",
"ip_address": "10.0.0.3",
"gateway": "10.0.0.1",
"uptime_ms": 19425000,
"rssi": -62
}
}
```
Subscribe to `vesper/+/status/heartbeat` to discover all online devices.
### Alert Payload (`vesper/{id}/status/alerts`)
Published only when a subsystem state changes. The server should store the active alert set per device and update the display in place rather than appending a log entry.
```json
{ "subsystem": "FileManager", "state": "WARNING", "msg": "ConfigManager health check failed" }
```
On recovery:
```json
{ "subsystem": "FileManager", "state": "CLEARED" }
```
`state` values: `WARNING` | `CRITICAL` | `FAILED` | `CLEARED`
A fault-class boot reset also publishes here — `subsystem: "System"`, e.g.:
```json
{ "subsystem": "System", "state": "WARNING", "msg": "Device reset due to fault: TASK_WATCHDOG" }
```
### Info Payload (`vesper/{id}/status/info`)
Published on significant device state changes. `type` identifies the event; `payload` is event-specific.
```json
{ "type": "playback_started", "payload": { "pid": "ormilia_1_8" } }
{ "type": "playback_stopped", "payload": {} }
{ "type": "boot_reason", "payload": { "reason": "POWERON" } }
```
`boot_reason` is published once, the first time MQTT connects after boot — only for expected reset reasons (`POWERON`, `SOFTWARE`, `DEEPSLEEP_WAKE`, `EXTERNAL_PIN`, `SDIO`, `UNKNOWN`). Fault reasons (`PANIC`, `TASK_WATCHDOG`, `INTERRUPT_WATCHDOG`, `OTHER_WATCHDOG`, `BROWNOUT`) go to `status/alerts` instead (see above).
| `vesper/{id}/status/heartbeat` | Every 30s (+ LWT on unclean disconnect) | 1 | yes | `heartbeat` |
| `vesper/{id}/status/playback` | On playback transition | 1 | yes | `playback` |
| `vesper/{id}/control/reports` | Critical unsolicited events (e.g. bell overload) | 1 | no | `reports` |
| `vesper/{id}/system/alerts` | On subsystem state change only | 1 | yes, until cleared | `alerts` |
| `vesper/{id}/system/info` | On discrete device state events (e.g. boot report) | 1 | yes | `info` |
| `vesper/{id}/system/logs` | Mirrors serial log stream | 0 | no | `logs` |
| `vesper/{id}/system/metrics` | Every 5 min — CPU temp, WiFi/OTA state, bell heat | 0 | no | `metrics` |
| `vesper/{id}/control/ack` | Reply to every command (strictly request/response) | 1 | no | `command` |
---
+200 -82
View File
@@ -1,70 +1,148 @@
# Vesper — MQTT Events Reference
# Vesper — MQTT Events Reference (v2)
> 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
> Companion spec: [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md) — topic table, per-topic ON/OFF switches, `req_id` correlation, LWT.
> Last updated: 2026-09-21 (v2 topic rebuild — see F-062 in [feature-catalog.md](../features/feature-catalog.md))
---
## Overview
Vesper publishes on four MQTT topics. All topics are device-scoped under the prefix `vesper/{device_id}/`.
Vesper publishes on eight MQTT topics (a ninth, `system/ota`, is reserved but not yet built). 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 |
| Topic | Direction | QoS | Retained | Switch | Purpose |
|-------|-----------|-----|----------|--------|---------|
| `vesper/{id}/control/command` | Inbound | 1 | no | `command` | Commands from server/app — board only ever receives here |
| `vesper/{id}/control/ack` | Outbound | 1 | no | `command` | Replies to commands **only** — strictly request/response |
| `vesper/{id}/control/reports` | Outbound | 1 | no | `reports` | Critical, unsolicited, time-sensitive board-initiated events (e.g. bell overload) |
| `vesper/{id}/status/heartbeat` | Outbound | 1 | yes | `heartbeat` | Periodic liveness + state signal. Also carries LWT. |
| `vesper/{id}/status/playback` | Outbound | 1 | yes | `playback` | Playback transitions only |
| `vesper/{id}/system/alerts` | Outbound | 1 | yes, until cleared | `alerts` | Subsystem state-change events |
| `vesper/{id}/system/info` | Outbound | 1 | yes | `info` | Discrete device state events (boot report, etc.) |
| `vesper/{id}/system/logs` | Outbound | 0 | no | `logs` | Full log stream, mirrors serial log output |
| `vesper/{id}/system/metrics` | Outbound | 0 | no | `metrics` | Structured telemetry — fleet-health graphing |
Subscribe to `vesper/+/status/#` to receive all status events from all devices.
Subscribe to `vesper/+/#` to receive everything from all devices (fleet webserver pattern). The phone app subscribes only to `control/ack`, `status/heartbeat`, `status/playback`.
Every topic above except `control/command`/`control/ack` (which share one switch, `command`) has its own independent ON/OFF publish switch — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md#per-topic-onoff-switches) for the full mechanism (`mqtt.get_topics`/`mqtt.set_topics`).
---
## `vesper/{id}/status/heartbeat`
**QoS:** 1 — **Retained:** yes — **Interval:** 30 seconds
**QoS:** 1 — **Retained:** yes — **Interval:** 30 seconds — **Switch:** `heartbeat`
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.
Published immediately on MQTT connect, then every 30 seconds. The broker retains the last message so any new subscriber instantly sees the device's last known state. Also the LWT target — see [LWT](#last-will-and-testament-lwt) below.
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)
- Raise an offline alert if no heartbeat is received within 90 seconds (3 missed beats), or immediately on receiving an LWT-triggered `state: "offline"` message
### Payload
Flat — no envelope wrapper (the topic is the discriminator).
```json
{
"device_id": "BSVSPR-26E11J-STD10R-M4SC2Z",
"state": "idle",
"ok": true,
"fw_version": "2.2.0",
"uptime_ms": 19425000,
"uptime_human": "5h 23m 45s",
"ip_address": "10.0.0.3",
"gateway": "10.0.0.1",
"rssi": -62,
"free_heap": 142000
}
```
| Field | Type | Description |
|-------|------|-------------|
| `device_id` | string | Device serial number (from NVS) |
| `state` | string | `idle` \| `playing` \| `paused` \| `error` \| `booting` — independently derived from `Player`/`HealthMonitor`, never mirrored from `status/playback` or `system/alerts` |
| `ok` | bool | Overall device health (`HealthMonitor::isFirmwareStable()`), independent of playback state |
| `fw_version` | string | Firmware SemVer string |
| `uptime_ms` | integer | Milliseconds since boot |
| `uptime_human` | string | Human-readable uptime, e.g. `"5h 23m 45s"` |
| `ip_address` | string | Current device IP |
| `gateway` | string | Network gateway IP |
| `rssi` | integer | WiFi signal strength (dBm) |
| `free_heap` | integer | Free heap in bytes |
### Last Will and Testament (LWT)
Registered on every `begin()`/reconnect. If the connection drops **uncleanly** (crash, power loss, network loss), the broker automatically publishes:
```json
{ "device_id": "BSVSPR-26E11J-STD10R-M4SC2Z", "state": "offline", "ok": false }
```
to `status/heartbeat` (QoS 1, retained), overwriting the last "online" heartbeat. For **intentional** disconnects (e.g. `mqtt.disable`), the firmware explicitly publishes the same payload before disconnecting, since LWT does not fire on a clean disconnect.
---
## `vesper/{id}/status/playback`
**QoS:** 1 — **Retained:** yes — **Switch:** `playback` — **Trigger:** playback state transition only
Published by `Player::setStatus()` on every transition (not polled).
### Payload
```json
{ "action": "playing", "time_elapsed": 12, "projected_run_time": 45000 }
```
| Field | Type | Description |
|-------|------|-------------|
| `action` | string | `playing` \| `paused` \| `idle` |
| `time_elapsed` | integer | Seconds since playback started (0 for `idle`) |
| `projected_run_time` | integer | Projected total run time in ms (0 if not applicable) |
---
## `vesper/{id}/control/reports`
**QoS:** 1 — **Retained:** no — **Switch:** `reports` — **Trigger:** critical, time-sensitive, board-initiated event
The opposite of `control/command`: unsolicited data the board sends because it needs to be read *now*. Not a reply to anything — never carries `req_id`. Not retained, since it's an event stream, not a status snapshot.
### Envelope
```json
{ "type": "event_type", "payload": { ... } }
```
### Bell overload event
Published by `CommunicationRouter::sendBellOverloadNotification()` → `publishReport("bell_overload", ...)` when per-bell strike load exceeds configured thresholds.
```json
{
"status": "INFO",
"type": "heartbeat",
"type": "bell_overload",
"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
"bells": [2, 5],
"loads": [54, 48],
"severity": "WARNING"
}
}
```
| 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 |
| `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) |
---
## `vesper/{id}/status/alerts`
## `vesper/{id}/system/alerts`
**QoS:** 1 — **Retained:** no — **Trigger:** subsystem state change only
**QoS:** 1 — **Retained:** yes, until cleared — **Switch:** `alerts` — **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.
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, or the `alerts` switch is off, at the moment of the transition. Retained so a late-connecting console (fleet webserver) immediately sees the last unresolved alert per subsystem.
The server should:
- Maintain a **per-device active alert set** (e.g. a dict keyed by `subsystem`)
@@ -75,25 +153,18 @@ The server should:
### Alert payload (problem)
```json
{
"subsystem": "FileManager",
"state": "WARNING",
"msg": "ConfigManager health check failed"
}
{ "subsystem": "FileManager", "state": "WARNING", "msg": "ConfigManager health check failed" }
```
### Cleared payload (recovery)
```json
{
"subsystem": "FileManager",
"state": "CLEARED"
}
{ "subsystem": "FileManager", "state": "CLEARED" }
```
| Field | Type | Description |
|-------|------|-------------|
| `subsystem` | string | Subsystem name. One of: `BellEngine`, `OutputManager`, `Player`, `Communication`, `TimeKeeper`, `Telemetry`, `OTAManager`, `Networking`, `ConfigManager`, `FileManager` |
| `subsystem` | string | Subsystem name. One of: `BellEngine`, `OutputManager`, `Player`, `Communication`, `TimeKeeper`, `Telemetry`, `OTAManager`, `Networking`, `ConfigManager`, `FileManager`, `System` |
| `state` | string | New state: `WARNING` \| `CRITICAL` \| `FAILED` \| `CLEARED` |
| `msg` | string | Human-readable description. Absent when `state` is `CLEARED`. |
@@ -121,89 +192,136 @@ The server should:
| OTAManager | no | OTA update subsystem |
| Networking | no | WiFi connectivity |
A fault-class boot reset also publishes here — `subsystem: "System"`, e.g.:
```json
{ "subsystem": "System", "state": "WARNING", "msg": "Device reset due to fault: TASK_WATCHDOG" }
```
---
## `vesper/{id}/status/info`
## `vesper/{id}/system/info`
**QoS:** 0 — **Retained:** no — **Trigger:** significant device state change
**QoS:** 1 — **Retained:** yes — **Switch:** `info` — **Trigger:** discrete device state event
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.
Published for general device state changes that are not health failures and not quantitative telemetry (see `system/metrics` for that). Use this topic to update the device detail panel (e.g. boot reason) without polling.
### Envelope
```json
{ "type": "event_type", "payload": { ... } }
```
### `boot_report`
Published once, the first time MQTT connects after boot (guarded, not repeated on reconnect).
```json
{
"type": "event_type",
"payload": { ... }
"type": "boot_report",
"payload": {
"boot_count": 47,
"reset_reason": "PANIC",
"is_fault": true,
"free_heap": 187234,
"crash": { "task": "TelemetryTask", "pc": 1074111832, "exc_cause": 1, "exc_vaddr": 0 }
}
}
```
### 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.
`crash` is present only when a coredump was found for the crash that caused this boot — omitted on a clean/expected reset or a fault reset with no coredump (e.g. brownout). A fault-class reset additionally publishes a `system/alerts` WARNING (see above) — `system/info`'s `boot_report` is published unconditionally, fault or not.
---
## `vesper/{id}/data`
## `vesper/{id}/system/logs`
**QoS:** 0 — **Retained:** no
**QoS:** 0 — **Retained:** no — **Switch:** `logs`
Published in response to commands and for unsolicited events that are not health-related.
### Command response envelope
Mirrors the serial log stream, respecting both the configured MQTT log level (`log.set_mqtt`, 0–5) and this topic's own ON/OFF switch independently — the switch can silence the whole channel without touching the configured level. See [Logging](../../src/Logging/README.md).
```json
{
"status": "SUCCESS" | "ERROR",
"type": "command_name",
"payload": { ... }
}
{ "level": "WARNING", "subsystem": "BellEngine", "message": "...", "timestamp": 12345 }
```
### Bell overload event
`timestamp` is `millis()` (ms since boot), not wall-clock time.
Published by `CommunicationRouter::sendBellOverloadNotification()` when per-bell strike load exceeds configured thresholds.
---
## `vesper/{id}/system/metrics`
**QoS:** 0 — **Retained:** no — **Switch:** `metrics` — **Interval:** 5 minutes
Structured telemetry for fleet-health graphing — not consumed by the phone app. Published by `CommunicationRouter::reportDiagnosticsIfDue()`.
```json
{
"status": "INFO",
"type": "bell_overload",
"payload": {
"bells": [2, 5],
"loads": [54, 48],
"severity": "WARNING"
}
"cpu_temp": { "avg": 47.1, "min": 44.8, "max": 52.8, "samples": 20 },
"wifi_reconnects": { "lifetime_count": 2, "last_reason": "AUTH_EXPIRE", "last_at_uptime_ms": 3600000 },
"ota": { "current_version": "2.2.0", "update_available": false, "last_check_uptime_ms": 180000, "last_error": "NONE" },
"stack_high_water": { "TelemetryTask": 1024, "HealthMonitor": 890 },
"bell_strikes": { "0": 1234, "1": 567 },
"bell_loads": { "0": 12, "1": 0 },
"cooling_active": false
}
```
| 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) |
| `cpu_temp` | object | Min/max/avg CPU die temperature (°C) since the last report |
| `wifi_reconnects` | object | Lifetime-this-boot reconnect count, last disconnect reason/uptime |
| `ota` | object | Current/available version, update-available flag, last check time, last error |
| `stack_high_water` | object | Bytes free per registered task (low-water mark) |
| `bell_strikes` | object | Cumulative strike count per bell channel (0–15) |
| `bell_loads` | object | Current heat-load accumulator per bell channel |
| `cooling_active` | bool | True if any bell still has residual heat |
---
## `vesper/{id}/control/command` and `vesper/{id}/control/ack`
**QoS:** 1 — **Retained:** no — **Switch:** `command`
`control/command` is read-only from the board's perspective — the board only ever receives here. `control/ack` is strictly reply-only: every message on it answers a specific request (including `pong`), and no unsolicited event is ever published there. Both support an optional `req_id` field for correlation — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md#req_id-correlation).
### Command (inbound)
```json
{ "v": 2, "cmd": "playback", "req_id": "abc123", "contents": { "action": "stop" } }
```
### Reply (outbound)
```json
{ "status": "SUCCESS", "type": "playback", "req_id": "abc123", "message": "Command executed" }
```
`req_id` only appears in the reply if the request included one. Bus-wide unsolicited broadcasts (`CommandBus::broadcast()`) also publish here, with the same envelope shape and no `req_id` — but purpose-specific events (playback, alerts, reports, metrics) never use this path; they publish directly to their own topics instead.
---
## 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
vesper/+/status/heartbeat → update last_seen + state/ok, no logging (unless state:"offline" from LWT)
vesper/+/status/playback → update device detail panel's playback state
vesper/+/control/reports → surface immediately — critical, time-sensitive (e.g. bell_overload)
vesper/+/system/alerts → upsert/remove active alert set per device
vesper/+/system/info → update device state panel (boot_report, etc.)
vesper/+/system/logs → remote log viewer / archival
vesper/+/system/metrics → fleet-health graphing / time-series storage
vesper/+/control/ack → command responses only (phone app / whoever issued the command)
```
---
## Migration from v1 topics
See [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md#migration-from-v1) for the full old→new topic mapping. Summary: `control`→`control/command`, `data`→`control/ack` (+ new `control/reports` and `status/playback` split out), `status/alerts`→`system/alerts`, `status/info`→`system/info` (diagnostics moved to new `system/metrics`), plus new `system/logs`.
---
## 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 |
| *(entire v1 topic set: `control`, `data`, `status/alerts`, `status/info`)* | — | v2.2.0 | Replaced wholesale by the v2 topic spec — see F-062 in [feature-catalog.md](../features/feature-catalog.md) |
@@ -0,0 +1,75 @@
# Vesper MQTT Topic Specification v2
Reference for firmware implementation. Device ID placeholder: `{device_id}`.
Implemented in [MQTTDriver](../../src/Communication/Drivers/MQTTDriver/README.md) (topic strings, LWT, heartbeat)
and [MQTTTransport](../../src/Communication/Transport/MQTTTransport/README.md) (command/ack dispatch, req_id).
## Topic Table
| Topic | Purpose | QoS | Retain | Switch | Notes |
|---|---|---|---|---|---|
| `vesper/{device_id}/control/command` | Inbound commands (play, stop, ping, etc.) | 1 | No | `command` | **Read-only from the board's perspective — the board only receives here, never publishes.** Includes optional `req_id` for correlation. `v`, `cmd`, `contents` as before. |
| `vesper/{device_id}/control/ack` | Replies to commands, including `pong` | 1 | No | `command` | **Strictly replies only — every message here answers a specific request, and every reply goes here. Nothing unsolicited is ever published to this topic.** Echoes `req_id` from the originating command when one was sent. `status: SUCCESS/ERROR/INFO`, `type`, optional `message`/`data`. |
| `vesper/{device_id}/control/reports` | Critical, time-sensitive board-initiated events (e.g. bell overload) | 1 | No | `reports` | The opposite of `control/command` — unsolicited data the board sends because it needs to be read *now*. Not a reply to anything, no `req_id`. Not retained — an event stream, not a status snapshot. |
| `vesper/{device_id}/status/heartbeat` | Periodic health/state summary, every 30s | 1 | **Yes** | `heartbeat` | Also carries LWT (see below). Fields: `device_id`, `state` (`idle`/`playing`/`paused`/`error`/`booting`), `ok` (bool), `fw_version`, `uptime_ms`, `uptime_human`, `ip_address`, `gateway`, `rssi`, `free_heap` — `state`/`ok` independently derived, never mirrored from `status/playback` or `system/alerts`. |
| `vesper/{device_id}/status/playback` | Playback state transitions only | 1 | **Yes** | `playback` | `action`: `playing`/`paused`/`idle`, plus `time_elapsed`, `projected_run_time`. Published on transition, not polled. |
| `vesper/{device_id}/system/alerts` | Subsystem state changes (warnings/errors) | 1 | **Yes**, until cleared | `alerts` | Published on transition only (WARNING/CRITICAL/FAILED/CLEARED). Not consumed by phone app — webserver/fleet only. |
| `vesper/{device_id}/system/info` | Discrete system events (e.g. `boot_report`) | 1 | **Yes** | `info` | Not consumed by phone app. Excludes errors (those go to `alerts`) and metrics (those go to `metrics`). |
| `vesper/{device_id}/system/logs` | Full log stream, serial-log equivalent | 0 | No | `logs` | Not consumed by phone app. Respects device's configured log level (`log.set_mqtt`) **and** this on/off switch independently — the switch can silence the whole channel without touching the configured level. Should not compete with heap/buffer needed for command traffic — guard same as `hasHeapForPublish()`. |
| `vesper/{device_id}/system/metrics` | Structured telemetry (heap free, WiFi RSSI, CPU temp, WiFi reconnects, OTA state, stack high-water marks, bell strike/heat data) | 0 | No | `metrics` | Not consumed by phone app. For fleet-health graphing on webserver. Published every 5 minutes by the existing diagnostics-report mechanism — see [CommunicationRouter](../../src/Communication/CommunicationRouter/README.md). |
| `vesper/{device_id}/system/ota` | OTA update status | 1 | No (transient by nature) | — | Not consumed by phone app. Reserved topic — build only once OTA-over-MQTT capability exists. States: e.g. `downloading`/`flashing`/`rebooting`/`failed`. No switch yet (doesn't exist).
## Per-Topic ON/OFF Switches
Every topic above (except the not-yet-built `system/ota`) has an independent publish switch, persisted in `ConfigManager::MqttTopicConfig` (SD: `generalConfig.json` → `mqttTopics`; NVS on no-SD boards: packed bitfield at key `gc_mtop`). Default: all on.
- **Master + sub-switches.** `mqtt.enable`/`mqtt.disable` remains the master kill switch — it disconnects the broker entirely. The per-topic switches below only take effect *while the master switch is on*; they prune which topics publish, not whether the device is connected at all.
- **`command` covers both directions.** One switch, `command`, gates `control/command` (the subscription) and `control/ack` (its replies) together — turning it off unsubscribes from `control/command` live (no reconnect needed) and drops any reply that would have gone to `control/ack`.
- **Read current state:** `mqtt.get_topics` — returns all 8 switches as booleans.
- **Change state:** `mqtt.set_topics` — partial update, only send the fields you want to change:
```json
{ "v": 2, "cmd": "mqtt.set_topics", "contents": { "heartbeat": true, "metrics": false } }
```
Persisted to SD/NVS immediately. The `command` switch also applies live (subscribe/unsubscribe) without waiting for a reconnect; the others are simply checked on each publish attempt.
This lets a device "breathe" — a fleet-monitoring-only install with no phone app can turn off `command` entirely; a bandwidth-constrained site can turn off `logs` and `metrics` while keeping `heartbeat` and `command` alive.
## req_id Correlation
`control/command` and `control/ack` both support an optional `req_id` string field for correlating a reply to its request:
```json
{ "v": 2, "cmd": "ping", "req_id": "abc123", "contents": {} }
```
```json
{ "status": "SUCCESS", "type": "pong", "req_id": "abc123" }
```
- **Always optional.** A request without `req_id` gets a reply without `req_id` — this is deliberate so v1 clients and any caller not fanning requests out over a shared channel keep working unchanged.
- **Bus-wide, not MQTT-only.** `req_id` lives on `CommandEnvelope`/`CommandResult` in the shared `CommandBus` core (see [CommandBus](../../src/Communication/CommandBus/README.md)), not bolted onto MQTT alone — the intent is that any transport where multiple logical senders share one channel (multiple devices on one broker; a future multiplexed transport) can use the same mechanism to route replies.
- **No access control yet.** Any caller can set any `req_id` today. If needed later, safeguards (e.g. restricting who may set one, or validating format) can be added without a wire-format change.
## Cross-Cutting Notes
- **LWT (Last Will and Testament)**: on connect, register Last Will → publishes to `status/heartbeat` with `{"device_id": "...", "state": "offline", "ok": false}` (retained), fired by the broker only on an *unclean* disconnect. Re-registered automatically on every reconnect (AsyncMqttClient resends the Will on every CONNECT).
- **Graceful disconnect**: if the firmware ever disconnects intentionally (e.g. `mqtt.disable`, before OTA), it explicitly publishes the same offline payload before disconnecting, since LWT won't fire for clean disconnects. See `MQTTDriver::disconnect(bool graceful)`.
- **Subscribers**:
- Phone app subscribes only to `control/ack`, `status/heartbeat`, `status/playback` (+ publishes to `control/command`).
- Fleet webserver subscribes to everything via `vesper/+/#`, including `control/reports`, `system/alerts`, `system/info`, `system/logs`, `system/metrics`.
## Migration from v1
The previous topic set (`control` in, `data` out, plus `status/alerts` and `status/info`) is fully replaced by this spec — there is no dual-publish period. See [communication-refactor-plan.md](../architecture/communication-refactor-plan.md) for the wire-protocol migration this topic change shipped alongside, and the console's API Reference → Transports → Legacy tab for what will eventually document the pre-v2 shape for historical reference.
| v1 topic | v2 topic |
|---|---|
| `vesper/{id}/control` (in) | `vesper/{id}/control/command` |
| `vesper/{id}/data` (out — replies + broadcasts mixed) | `vesper/{id}/control/ack` (replies + bus-wide broadcasts) — purpose-specific broadcasts moved to their own topics below |
| `vesper/{id}/status/heartbeat` | `vesper/{id}/status/heartbeat` (same topic, new field shape — see table above) |
| *(none — playback transitions were mixed into `data`)* | `vesper/{id}/status/playback` |
| *(none — bell overload etc. were mixed into `data`)* | `vesper/{id}/control/reports` |
| `vesper/{id}/status/alerts` | `vesper/{id}/system/alerts` |
| `vesper/{id}/status/info` | `vesper/{id}/system/info` |
| *(none)* | `vesper/{id}/system/logs` |
| *(none — diagnostics report was on `status/info`)* | `vesper/{id}/system/metrics` |