- 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>
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>
Invalid JSON or a missing 'cmd' field on control/command previously logged
a WARNING on serial and returned with no reply at all — a client waiting
on control/ack had no way to tell "malformed request" apart from "message
never arrived" or "device offline," all three looking identical until its
own timeout fired.
Both onMessage() drop paths now publish an ERROR to control/ack before
returning: { "status": "ERROR", "type": "parse_error", "message": "..." }.
Unparseable JSON necessarily has no req_id (nothing to read it from); a
valid-but-cmd-less message echoes req_id if one was present. The heap-guard
drop above these two (hasHeapForPublish() check) is untouched — that one's
silence is deliberate, protecting against allocation under critical heap
pressure (see F-055), not something this fix should touch.
Bumped to v2.2.1. Verified: pio run -e vesper-std-v1 -e agnus-v1 both build clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Full MQTT topic rebuild per docs/reference/vesper_mqtt_topic_spec_v2.md.
Only the MQTT transport path changed — WebSocket, HTTP, and UART are untouched.
- control/command (in) + control/ack (out, strictly replies) replace the old
control/data pair; new control/reports for critical unsolicited events
(bell overload) that don't belong on the strictly-reply ack channel
- status/playback split out for playback transitions only
- status/alerts + status/info renamed to system/alerts + system/info, both
now correctly retained; new system/logs and system/metrics (diagnostics
report moved here from system/info, gained bell strike/heat data)
- LWT registered for the first time — status/heartbeat gets
{"state":"offline","ok":false} on an unclean disconnect; graceful
disconnect (mqtt.disable) announces offline explicitly since LWT doesn't
fire on a clean disconnect
- heartbeat payload flattened, gains independently-derived state/ok fields
(via a new MQTTDriver::setStateProvider() wired from Player+HealthMonitor)
- optional req_id correlation added bus-wide (CommandEnvelope/CommandResult),
not MQTT-only, since any transport with multiple senders sharing one
channel has the same problem. Always optional — v1 clients unaffected.
- per-topic ON/OFF switches (ConfigManager::MqttTopicConfig, 8 flags) as
sub-switches under the existing mqtt.enable/disable master switch, so a
device can breathe by disabling topics it doesn't need. New
mqtt.get_topics/mqtt.set_topics commands; command switch applies live.
Bumped to v2.2.0. Verified: pio run -e vesper-std-v1 -e agnus-v1 both build clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Decoded a new crash via addr2line against the exact flashed ELF:
console reported faulting task "async_tcp", cause 29, vaddr 0. Full
backtrace traced through AsyncTCP's _async_service_task ->
AsyncMqttClient::_onData -> MQTTTransport::onMessage ->
CommandBus::dispatch -> the reply path -> MQTTDriver::publish ->
AsyncMqttClient::publish -> PublishOutPacket's vector::reserve ->
operator new failing -> unhandled C++ exception -> abort().
Root cause is heap fragmentation, not a single bad allocation: rapid
relay.test_bell commands with Verbose/Debug logging meant every
command triggered ~4-5 JsonDocument/String allocations (RX log,
dispatch log, handler log, MQTT log-channel copies, reply publish),
all on AsyncTCP's own task, faster than the allocator could coalesce
freed blocks between cycles. Two "JSON parse error: NoMemory"
warnings preceded the abort by seconds - an early symptom of the same
fragmentation.
Checked why this can't be a catchable exception: this SDK build has
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0, so when the heap is
too fragmented to even allocate the object needed to throw
std::bad_alloc, it aborts instead of throwing. That's baked into the
precompiled Arduino-ESP32 core; fixing it means rebuilding the whole
ESP-IDF core from source, judged out of scope. Chose prevention over
a catchable-exception fix.
Adds MQTTDriver::hasHeapForPublish() (20KB threshold, chosen with
margin above the ~62KB-free-but-already-fragmented state seen at
crash time) and applies it before every allocation-heavy publish path
(publish, publishDirect, publishHeartbeat) and before MQTTTransport::
onMessage() does its own incoming-command deserialization. Skip
warnings use Serial.printf directly, not LOG_*, to avoid recursing
into the same low-heap condition via MQTT-channel logging.
Also corrects how coredump crash detail should be read for abort()-
reached crashes (vs. true hardware exceptions like the F-051 stack
canary trip): pc/exc_cause/exc_vaddr describe abort() internals in
this case, not the original fault site - only the task name is
reliably the "real" crash location. Documented for console/dashboard
consumers in feature-catalog.md F-055.
A full fix (queueing incoming commands off AsyncTCP's task, mirroring
the F-051 logging-queue redesign) is scoped out as a documented
future improvement, not rushed into this change.
Verified: pio run on vesper-std-v1 and agnus-v1.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add inline documentation for all src/ subsystems covering purpose,
responsibilities, public API, and usage notes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>