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.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user