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:
@@ -22,6 +22,7 @@ See [docs/reference/vesper_mqtt_topic_spec_v2.md](../../../../docs/reference/ves
|
||||
| `void connect()` | Calls `AsyncMqttClient::connect()`. No-op if MQTT is disabled in config or already connected. |
|
||||
| `void disconnect(bool graceful = false)` | Disconnects. If `graceful` is true, explicitly publishes the retained offline payload to `status/heartbeat` first — see [Graceful disconnect](#graceful-disconnect). |
|
||||
| `uint16_t publishAck(const String& payload, int qos = 0, bool retain = false)` | Publishes a reply to `control/ack`. Returns packet ID, or 0 on failure (not connected, low heap, or the `command` topic switch is off). |
|
||||
| `uint16_t publishConfirmed(const String& fullTopic, const String& payload, bool retain, bool resendOnReconnect)` | QoS 1 publish with PUBACK tracking (8 s deadline). A missed deadline makes the supervisor reset the connection. `resendOnReconnect=true` keeps the message and republishes it after the reconnect (event topics); `false` for retained state the caller republishes itself on connect. Used for `status/playback` (false) and `control/reports` (true). |
|
||||
| `uint16_t publishDirect(const String& fullTopic, const String& payload, int qos = 0, bool retain = false)` | Publishes to an absolute, fully-qualified topic (no prefix applied) — no topic-switch gating here; the caller (`CommunicationRouter`) checks the relevant switch before calling. Same heap guard as `publishAck()`. |
|
||||
| `bool hasHeapForPublish() const` | Returns `true` if `ESP.getFreeHeap() >= MIN_FREE_HEAP_FOR_PUBLISH` (20KB). Public so `MQTTTransport` can apply the same threshold before its own allocation-heavy work (JSON deserialization of incoming commands) without duplicating the constant. See [Gotchas](#gotchas--notes) below for why this exists. |
|
||||
| `const String& getCommandTopic() const` / `getAckTopic()` / `getHeartbeatTopic()` / `getPlaybackTopic()` / `getReportsTopic()` / `getAlertsTopic()` / `getInfoTopic()` / `getLogsTopic()` / `getMetricsTopic()` | Cached full topic strings, available after `begin()`. |
|
||||
@@ -69,13 +70,13 @@ The supervisor forces a reset (`AsyncMqttClient::disconnect(true)`, then a norma
|
||||
| Condition | Why it happens |
|
||||
|---|---|
|
||||
| A connect attempt produced neither CONNACK nor a disconnect callback within 30 s (`"connect attempt stuck"`) | AsyncMqttClient ignores `AsyncClient::connect()`'s return value and stays in CONNECTING forever if it fails (e.g. lwIP out of PCBs); a failed `tcp_close` never fires onDisconnect. Every later `connect()` is then a silent no-op. |
|
||||
| The heartbeat's PUBACK hasn't arrived 20 s after it was sent (`"heartbeat PUBACK timeout"`) | Half-open socket or stalled send queue while the library still reports CONNECTED. |
|
||||
| A tracked QoS 1 publish has no PUBACK by its deadline: heartbeat 20 s (`"heartbeat PUBACK timeout"`), playback / report 8 s (`"playback PUBACK timeout"`, `"report PUBACK timeout"`) | Half-open socket or stalled send queue while the library still reports CONNECTED. |
|
||||
|
||||
Counters and last reasons are reported by `mqtt.status`.
|
||||
|
||||
### QoS policy
|
||||
|
||||
All publishes are QoS 0 except the heartbeat. This AsyncMqttClient build sends its queue strictly in order and holds every later packet until a QoS 1 PUBACK arrives, and `_onPubAck()` doesn't kick the queue — the next packet waits for the ~500 ms TCP poll. A burst of QoS 1 messages (playback + ack + log lines) cost RTT + up to 500 ms *each*. With `cleanSession=true` on both device and backend, QoS 1 never provided redelivery anyway.
|
||||
QoS 1 only for the heartbeat, `status/playback` and `control/reports`, all with PUBACK tracking; everything else QoS 0. The library sends its queue strictly in order and holds later packets until a QoS 1 PUBACK arrives, so each QoS 1 message costs whatever is behind it one round trip. Upstream also waited for the next ~500 ms TCP poll after each PUBACK; the vendored copy in `lib/AsyncMqttClient` is patched to send immediately (see its `VENDORED.md`). Plain QoS 1 recovers nothing here — with `cleanSession=true` the library drops unacked packets on reconnect — which is why delivery is guaranteed by the tracking + reset + republish/resend path instead.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user