fix(MQTT): self-recovering supervisor, LWT payload fix, QoS 0 publishes (F-071, F-072)
Device went cloud-silent after days of uptime while WebSocket kept working; last thing on status/heartbeat was garbage. Causes and fixes: - LWT payload was a dangling pointer: setWill() stores the raw char*, begin() passed a temporary String. The broker published freed heap as the Will on the unclean drop. Now held in _willPayload. - Reconnect/stabilisation/heartbeat timers each xTaskCreate()d a short-lived task with the result ignored; one failed allocation ended the one-shot reconnect chain for good. Replaced by one persistent supervisor task that polls WiFi.status() itself, reconnects with backoff (cap now 60 s), sends the heartbeat, and force-resets the client when a connect attempt is stuck for 30 s or the heartbeat PUBACK is missing for 20 s. - New mqtt.status command (all transports) exposes connect/disconnect counters, last reasons and forced resets for post-mortems over WebSocket. Latency (F-072): AsyncMqttClient holds its queue behind every QoS 1 PUBACK and only resumes on the ~500 ms poll, so each QoS 1 message cost RTT + up to 500 ms. All publishes are now QoS 0 except the heartbeat (liveness probe); cleanSession=true on both ends meant QoS 1 never gave redelivery. WiFi modem sleep disabled on connect to remove DTIM-induced RX delays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,9 +80,9 @@ MQTT uses the v2 topic set — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_to
|
||||
| MQTT | `vesper/{device_id}/control/ack` | Outbound replies | Strictly request/response — nothing unsolicited |
|
||||
| MQTT | `vesper/{device_id}/control/reports` | Outbound, critical unsolicited events | `bell_overload`, `playback_failed` — not retained |
|
||||
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s + LWT |
|
||||
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 1 | Playback transitions |
|
||||
| MQTT | `vesper/{device_id}/system/alerts` | Outbound, retained until cleared, QoS 1 | Subsystem state-change events |
|
||||
| MQTT | `vesper/{device_id}/system/info` | Outbound, retained, QoS 1 | Discrete device events (boot report) |
|
||||
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 0 | Playback transitions |
|
||||
| MQTT | `vesper/{device_id}/system/alerts` | Outbound, retained until cleared, QoS 0 | Subsystem state-change events |
|
||||
| MQTT | `vesper/{device_id}/system/info` | Outbound, retained, QoS 0 | Discrete device events (boot report) |
|
||||
| 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 |
|
||||
| WebSocket | `ws://{device_ip}/ws` | Bidirectional | Send `identify` on connect |
|
||||
@@ -821,6 +821,12 @@ Returns `message: "MQTT enabled and saved"` / `"MQTT disabled and saved"`. Error
|
||||
|
||||
Returns `data: { "enabled", "host", "port", "user", "use_ssl" }` (never the password).
|
||||
|
||||
### `mqtt.status`
|
||||
|
||||
Connection health since boot — works on every transport, so it's the command to send over WebSocket when the cloud shows a device offline but the local app still works.
|
||||
Returns `data: { "enabled", "connected", "connected_for_ms", "connects", "disconnects", "reconnect_attempts", "last_disconnect_reason", "last_disconnect_ago_ms", "forced_resets", "last_forced_reset_reason", "last_forced_reset_ago_ms", "wifi_connected", "free_heap" }`.
|
||||
`*_ago_ms` and `connected_for_ms` are `0` when the event never happened / not connected. `last_forced_reset_reason` is `"connect attempt stuck"` or `"heartbeat PUBACK timeout"` (empty if self-recovery never fired). No errors.
|
||||
|
||||
### `mqtt.get_topics`
|
||||
|
||||
Returns `data: { "command", "heartbeat", "playback", "reports", "alerts", "info", "logs", "metrics" }` (bools).
|
||||
@@ -873,14 +879,16 @@ Published without a request, on the v2 topic set. Full field-level reference: [m
|
||||
| Topic | When | QoS | Retained | Switch |
|
||||
|---|---|---|---|---|
|
||||
| `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 (`bell_overload`, `playback_failed`) | 1 | no | `reports` |
|
||||
| `vesper/{id}/system/alerts` | On subsystem state change only | 1 | yes, until cleared | `alerts` |
|
||||
| `vesper/{id}/system/info` | Discrete device events (e.g. boot report) | 1 | yes | `info` |
|
||||
| `vesper/{id}/status/playback` | On playback transition | 0 | yes | `playback` |
|
||||
| `vesper/{id}/control/reports` | Critical unsolicited events (`bell_overload`, `playback_failed`) | 0 | no | `reports` |
|
||||
| `vesper/{id}/system/alerts` | On subsystem state change only | 0 | yes, until cleared | `alerts` |
|
||||
| `vesper/{id}/system/info` | Discrete device events (e.g. boot report) | 0 | yes | `info` |
|
||||
| `vesper/{id}/system/logs` | Mirrors serial log stream | 0 | no | `logs` |
|
||||
| `vesper/{id}/system/metrics` | Every 5 min | 0 | no | `metrics` |
|
||||
|
||||
`control/ack` carries only replies (it is not an event topic).
|
||||
`control/ack` carries only replies (it is not an event topic). Replies are published at QoS 0.
|
||||
|
||||
Everything the board publishes is QoS 0 except the heartbeat (QoS 1, its PUBACK doubles as a liveness probe) — see F-071 in the feature catalog for why.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ Vesper publishes on eight MQTT topics (a ninth, `system/ota`, is reserved but no
|
||||
| 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 (`bell_overload`, `playback_failed`) |
|
||||
| `vesper/{id}/control/ack` | Outbound | 0 | no | `command` | Replies to commands **only** — strictly request/response |
|
||||
| `vesper/{id}/control/reports` | Outbound | 0 | no | `reports` | Critical, unsolicited, time-sensitive board-initiated events (`bell_overload`, `playback_failed`) |
|
||||
| `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}/status/playback` | Outbound | 0 | yes | `playback` | Playback transitions only |
|
||||
| `vesper/{id}/system/alerts` | Outbound | 0 | yes, until cleared | `alerts` | Subsystem state-change events |
|
||||
| `vesper/{id}/system/info` | Outbound | 0 | 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 |
|
||||
|
||||
@@ -85,7 +85,7 @@ to `status/heartbeat` (QoS 1, retained), overwriting the last "online" heartbeat
|
||||
|
||||
## `vesper/{id}/status/playback`
|
||||
|
||||
**QoS:** 1 — **Retained:** yes — **Switch:** `playback` — **Trigger:** playback state transition only
|
||||
**QoS:** 0 — **Retained:** yes — **Switch:** `playback` — **Trigger:** playback state transition only
|
||||
|
||||
Published by `Player::setStatus()` on every transition (not polled), **and on every MQTT connect/reconnect** with the Player's current real state — so a retained `playing` left behind by a power loss mid-melody is overwritten (normally with `idle`) as soon as the board is back. This topic — not the `control/ack` reply — is the source of truth for what the board is actually doing. Skipped (not queued) while free heap is below the publish guard.
|
||||
|
||||
@@ -151,7 +151,7 @@ On a SUCCESS play ACK the board publishes `status/playback` **before** the ACK:
|
||||
|
||||
## `vesper/{id}/control/reports`
|
||||
|
||||
**QoS:** 1 — **Retained:** no — **Switch:** `reports` — **Trigger:** critical, time-sensitive, board-initiated event
|
||||
**QoS:** 0 — **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.
|
||||
|
||||
@@ -201,7 +201,7 @@ Like every `control/reports` event it carries no `req_id` — correlate with the
|
||||
|
||||
## `vesper/{id}/system/alerts`
|
||||
|
||||
**QoS:** 1 — **Retained:** yes, until cleared — **Switch:** `alerts` — **Trigger:** subsystem state change only
|
||||
**QoS:** 0 — **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, 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.
|
||||
|
||||
@@ -262,7 +262,7 @@ A fault-class boot reset also publishes here — `subsystem: "System"`, e.g.:
|
||||
|
||||
## `vesper/{id}/system/info`
|
||||
|
||||
**QoS:** 1 — **Retained:** yes — **Switch:** `info` — **Trigger:** discrete device state event
|
||||
**QoS:** 0 — **Retained:** yes — **Switch:** `info` — **Trigger:** discrete device state event
|
||||
|
||||
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.
|
||||
|
||||
@@ -350,7 +350,7 @@ Structured telemetry for fleet-health graphing — not consumed by the phone app
|
||||
|
||||
## `vesper/{id}/control/command` and `vesper/{id}/control/ack`
|
||||
|
||||
**QoS:** 1 — **Retained:** no — **Switch:** `command`
|
||||
**QoS:** 1 inbound (`control/command`), 0 outbound (`control/ack`) — **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).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user