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:
2026-10-15 21:07:14 +03:00
co-authored by Claude Opus 5.5
parent 09f562cf1d
commit cec4db4894
13 changed files with 382 additions and 258 deletions
+7
View File
@@ -383,6 +383,13 @@ void Networking::onWiFiConnected() {
setState(NetworkState::CONNECTED_WIFI);
setActiveConnection(ConnectionType::WIFI);
// Modem sleep off (the Arduino default is WIFI_PS_MIN_MODEM). With it on, the
// radio dozes between AP beacons and inbound packets wait for the next DTIM —
// 100ms to 1s+ per packet depending on the AP, which showed up as laggy app
// commands and status updates. Mains-powered device; the power cost is moot.
// Re-applied on every connect since WiFi.mode() changes can reset it.
WiFi.setSleep(false);
// Reset failure/phase counters on successful connection
_wifiConnectionFailures = 0;
_triedSavedCredentials = false;