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:
2026-10-15 21:50:54 +03:00
co-authored by Claude Opus 5.5
parent cec4db4894
commit c43d9ae11c
59 changed files with 2674 additions and 69 deletions
+44 -3
View File
@@ -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`