feat(MQTT): confirmed delivery for playback/reports; vendor AsyncMqttClient; pin all deps (F-073)
- MQTTDriver::publishConfirmed(): QoS 1 + PUBACK tracking (8 s; heartbeat 20 s). A missed PUBACK forces a reconnect. status/playback relies on the existing republish-current-state-on-connect; control/reports are resent after the next CONNACK (newest 4). Publish + registration under one recursive mutex since the PUBACK can arrive before publish() returns. - AsyncMqttClient vendored into lib/ (upstream 3d93fc7) with one patch: _onPubAck()/_onPubComp() call _handleQueue(), so a QoS 1 message delays the next packet by one RTT instead of RTT + up to ~500 ms. - platformio.ini: platform and every library pinned to the exact versions already being built (git deps by commit). Clean-libdeps rebuild verified to resolve the same AsyncTCP and the vendored AsyncMqttClient. - Removed board_build.cmake_extra_args (timer stack): no effect on Arduino builds, the SDK is precompiled with 2048. Replaced by a warning comment. - mqtt.status gains resent_messages and the new forced-reset reasons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -84,7 +84,8 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
|
||||
| F-069 | RF remote disabled on Vesper Standard builds (`HAS_RF=0`) — no fielded unit has a receiver; `rf.*` now only on agnus | v2.3.0 | Stable |
|
||||
| F-070 | Richer crash reports — coredump backtrace + ELF SHA, abort() reason string, and last pre-crash heap/uptime snapshot in `boot_report` and the SD boot log | v2.3.0 | Stable |
|
||||
| F-071 | MQTT self-recovery — single supervisor task replaces timer/task chain, wedge detection (stuck connect, missing heartbeat PUBACK), LWT payload fix, `mqtt.status` diagnostics | v2.3.0 | Stable |
|
||||
| F-072 | Lower status/reply latency — all MQTT publishes QoS 0 except heartbeat; WiFi modem sleep disabled | v2.3.0 | Stable |
|
||||
| F-072 | Lower status/reply latency — QoS 0 for non-critical MQTT topics; WiFi modem sleep disabled | v2.3.0 | Stable |
|
||||
| F-073 | Confirmed delivery for `status/playback` + `control/reports` (QoS 1, PUBACK tracked, reset + republish/resend); AsyncMqttClient vendored + patched; all dependencies pinned | v2.3.0 | Stable |
|
||||
|
||||
---
|
||||
|
||||
@@ -1457,7 +1458,8 @@ network stabilisation (it polls `WiFi.status()` itself, so it doesn't depend on
|
||||
- a connect attempt gets neither CONNACK nor a disconnect callback within 30 s (`"connect attempt stuck"`), or
|
||||
- the heartbeat's PUBACK is still missing 20 s after it was sent (`"heartbeat PUBACK timeout"`): a half-open
|
||||
socket or stalled send queue while the library still says CONNECTED. The heartbeat stays QoS 1 for this
|
||||
reason. With the `heartbeat` topic switch off, this probe is off too.
|
||||
reason. With the `heartbeat` topic switch off, this probe is off too. (F-073 adds the same check, 8 s,
|
||||
for playback and reports.)
|
||||
|
||||
**`mqtt.status`** (new command, all transports) returns connect/disconnect counters, last disconnect reason
|
||||
and age, forced-reset count/reason/age, WiFi state and free heap. If a device goes cloud-silent again, send
|
||||
@@ -1481,7 +1483,8 @@ log lines, each costing a round trip plus up to 500 ms. The PUBACK the board owe
|
||||
command waited in the same queue. With `cleanSession=true` on both the device and the backend
|
||||
(`backend/mqtt/client.py`), QoS 1 never bought redelivery: unacked packets are dropped on reconnect either way.
|
||||
|
||||
**Change.** Everything is published at QoS 0 except the heartbeat (QoS 1, see F-071). Topics, retain flags
|
||||
**Change.** Everything is published at QoS 0 except the heartbeat (QoS 1, see F-071). *Amended by F-073:
|
||||
`status/playback` and `control/reports` went back to QoS 1, with PUBACK tracking.* Topics, retain flags
|
||||
and payloads are unchanged. Subscribers receive at min(publish QoS, subscription QoS), so they now get QoS 0
|
||||
delivery, which changes nothing with clean sessions.
|
||||
|
||||
@@ -1491,3 +1494,41 @@ MQTT equally. `Networking::onWiFiConnected()` now calls `WiFi.setSleep(false)` o
|
||||
mains powered, so the extra ~80 mA doesn't matter.
|
||||
|
||||
Subsystem: `src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `src/Communication/Drivers/MQTTDriver/MQTTDriver.hpp`, `src/Logging/Logging.cpp`, `src/Networking/Networking.cpp`
|
||||
|
||||
### F-073 — Confirmed delivery for playback and reports; pinned dependencies
|
||||
|
||||
**Why.** F-072 moved everything except the heartbeat to QoS 0 for speed. Playback state is what the apps act
|
||||
on, so it must not get lost. QoS 0 can only lose a message in one situation: the connection has silently died
|
||||
but the device hasn't noticed yet. Plain QoS 1 doesn't save that message either — with `cleanSession=true` on
|
||||
both ends, AsyncMqttClient drops unacked packets on reconnect. Before this change, recovery depended on the
|
||||
20 s heartbeat probe plus the reconnect republish, so the app could show stale state for up to ~50 s.
|
||||
|
||||
**What changed.**
|
||||
|
||||
1. **`MQTTDriver::publishConfirmed()`** publishes at QoS 1 and records the packet ID with an 8 s deadline
|
||||
(heartbeat: 20 s). `onMqttPublish()` clears it on PUBACK. Publish and registration happen under one
|
||||
recursive mutex, because the PUBACK can arrive on the async_tcp task before `publish()` returns. A missed
|
||||
deadline makes the supervisor force-reset the connection. Up to 8 entries are tracked.
|
||||
2. **`status/playback`** uses it with no resend: on every connect `CommunicationRouter` already republishes
|
||||
the Player's *current* snapshot, and resending the old message would overwrite fresh retained state.
|
||||
Worst case for a lost transition is now ~8 s + reconnect, then the app gets the correct state.
|
||||
3. **`control/reports`** (`playback_failed`, `bell_overload`) uses it with resend: unconfirmed reports
|
||||
(newest 4) are republished right after the next CONNACK. Counted in `mqtt.status` as `resent_messages`.
|
||||
Reports raised while already disconnected are still dropped.
|
||||
4. **AsyncMqttClient vendored into `lib/AsyncMqttClient`** (upstream commit `3d93fc7`) and patched:
|
||||
`_onPubAck()`/`_onPubComp()` now call `_handleQueue()`. Upstream released the packet but waited for the
|
||||
next lwIP poll (~500 ms) to send the next one, so every QoS 1 message used to delay what was behind it by
|
||||
RTT + up to 500 ms; now it's just the RTT. Patches are marked `[vesper patch]`; see `VENDORED.md`.
|
||||
5. **Every dependency pinned to an exact version** in `platformio.ini`, including the platform
|
||||
(`espressif32 @ 6.12.0` = Arduino core 2.0.17). Git libraries (`ESPAsyncWebServer`, `AsyncTCP`) are pinned
|
||||
to the commits that were already being built. Nothing changes on a clean build unless a pin is edited in a
|
||||
commit. Verified by deleting `.pio/libdeps` and rebuilding: the same AsyncTCP (`3.3.2+sha.ef448a8`) and the
|
||||
vendored AsyncMqttClient are used.
|
||||
6. **Removed `board_build.cmake_extra_args`** (timer stack 4096). It only affects ESP-IDF framework builds;
|
||||
the Arduino SDK is precompiled with `CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048`, so it never did
|
||||
anything. Replaced by a comment: timer callbacks must only set flags or notify tasks.
|
||||
7. **WiFi and NTP timer callbacks retry** if `xTaskCreate()` fails (re-arm their one-shot timer), instead
|
||||
of silently ending the WiFi reconnect chain / skipping the NTP sync. Same failure mode as F-071.
|
||||
|
||||
Subsystem: `lib/AsyncMqttClient/`, `platformio.ini`, `src/Communication/Drivers/MQTTDriver/`,
|
||||
`src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `src/Networking/Networking.cpp`, `src/main.cpp`
|
||||
|
||||
@@ -80,7 +80,7 @@ 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 0 | Playback transitions |
|
||||
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 1 (confirmed) | 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 |
|
||||
@@ -824,8 +824,8 @@ Returns `data: { "enabled", "host", "port", "user", "use_ssl" }` (never the pass
|
||||
### `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.
|
||||
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", "resent_messages", "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"`, `"heartbeat PUBACK timeout"`, `"playback PUBACK timeout"` or `"report PUBACK timeout"` (empty if self-recovery never fired). `resent_messages` counts `control/reports` messages republished after a reconnect because their PUBACK never came. No errors.
|
||||
|
||||
### `mqtt.get_topics`
|
||||
|
||||
@@ -879,8 +879,8 @@ 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 | 0 | yes | `playback` |
|
||||
| `vesper/{id}/control/reports` | Critical unsolicited events (`bell_overload`, `playback_failed`) | 0 | no | `reports` |
|
||||
| `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 | 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` |
|
||||
@@ -888,7 +888,7 @@ Published without a request, on the v2 topic set. Full field-level reference: [m
|
||||
|
||||
`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.
|
||||
QoS 1 is used only for the heartbeat, `status/playback` and `control/reports`, and the firmware tracks their PUBACKs: a missing one makes the device reset the connection, republish the current playback state, and resend unconfirmed reports. Everything else is QoS 0 — see F-071/F-073 in the feature catalog.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ Vesper publishes on eight MQTT topics (a ninth, `system/ota`, is reserved but no
|
||||
|-------|-----------|-----|----------|--------|---------|
|
||||
| `vesper/{id}/control/command` | Inbound | 1 | no | `command` | Commands from server/app — board only ever receives here |
|
||||
| `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}/control/reports` | Outbound | 1 | 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 | 0 | yes | `playback` | Playback transitions only |
|
||||
| `vesper/{id}/status/playback` | Outbound | 1 | 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 |
|
||||
@@ -85,7 +85,7 @@ to `status/heartbeat` (QoS 1, retained), overwriting the last "online" heartbeat
|
||||
|
||||
## `vesper/{id}/status/playback`
|
||||
|
||||
**QoS:** 0 — **Retained:** yes — **Switch:** `playback` — **Trigger:** playback state transition only
|
||||
**QoS:** 1 (PUBACK tracked; current state republished on every reconnect) — **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:** 0 — **Retained:** no — **Switch:** `reports` — **Trigger:** critical, time-sensitive, board-initiated event
|
||||
**QoS:** 1 (PUBACK tracked; resent after a reconnect if unconfirmed) — **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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user