Files
project-vesper/docs/reference/mqtt-events.md
T
bonaminandClaude Opus 5.5 fe5ab6223c docs(playback): formally document the "stopping" status/playback state (F-065)
Player::setStatus() publishes action "stopping" when the run-time cap is
reached and BellEngine is finishing the current melody loop, but the spec
only listed playing/paused/idle. Kept it (not suppressed): it is a real
state that can last a whole loop while bells still ring, suppressing it on
MQTT alone would break WS/MQTT parity, and v1 tablets already know it.

Adds a state table (entry/exit, stop/play behaviour) to mqtt-events.md and
updates the topic spec and API reference. No firmware change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 20:10:03 +03:00

18 KiB
Raw Blame History

Vesper — MQTT Events Reference (v2)

Source of truth for all unsolicited MQTT messages published by Vesper firmware. Use this document to generate or update the AsyncAPI specification in the backend console. Companion spec: vesper_mqtt_topic_spec_v2.md — topic table, per-topic ON/OFF switches, req_id correlation, LWT. Last updated: 2026-09-21 (v2 topic rebuild — see F-062 in feature-catalog.md)


Overview

Vesper publishes on eight MQTT topics (a ninth, system/ota, is reserved but not yet built). All topics are device-scoped under the prefix vesper/{device_id}/.

Topic Direction QoS Retained Switch Purpose
vesper/{id}/control/command Inbound 1 no command Commands from server/app — board only ever receives here
vesper/{id}/control/ack Outbound 1 no command Replies to commands only — strictly request/response
vesper/{id}/control/reports Outbound 1 no reports Critical, unsolicited, time-sensitive board-initiated events (e.g. bell overload)
vesper/{id}/status/heartbeat Outbound 1 yes heartbeat Periodic liveness + state signal. Also carries LWT.
vesper/{id}/status/playback Outbound 1 yes playback Playback transitions only
vesper/{id}/system/alerts Outbound 1 yes, until cleared alerts Subsystem state-change events
vesper/{id}/system/info Outbound 1 yes info Discrete device state events (boot report, etc.)
vesper/{id}/system/logs Outbound 0 no logs Full log stream, mirrors serial log output
vesper/{id}/system/metrics Outbound 0 no metrics Structured telemetry — fleet-health graphing

Subscribe to vesper/+/# to receive everything from all devices (fleet webserver pattern). The phone app subscribes only to control/ack, status/heartbeat, status/playback.

Every topic above except control/command/control/ack (which share one switch, command) has its own independent ON/OFF publish switch — see vesper_mqtt_topic_spec_v2.md for the full mechanism (mqtt.get_topics/mqtt.set_topics).


vesper/{id}/status/heartbeat

QoS: 1 — Retained: yes — Interval: 30 seconds — Switch: heartbeat

Published immediately on MQTT connect, then every 30 seconds. The broker retains the last message so any new subscriber instantly sees the device's last known state. Also the LWT target — see LWT below.

The server should:

  • Update last_seen timestamp silently — no log entry, no display update
  • Raise an offline alert if no heartbeat is received within 90 seconds (3 missed beats), or immediately on receiving an LWT-triggered state: "offline" message

Payload

Flat — no envelope wrapper (the topic is the discriminator).

{
  "device_id": "BSVSPR-26E11J-STD10R-M4SC2Z",
  "state": "idle",
  "ok": true,
  "fw_version": "2.2.0",
  "uptime_ms": 19425000,
  "uptime_human": "5h 23m 45s",
  "ip_address": "10.0.0.3",
  "gateway": "10.0.0.1",
  "rssi": -62,
  "free_heap": 142000
}
Field Type Description
device_id string Device serial number (from NVS)
state string idle | playing | paused | error | booting — independently derived from Player/HealthMonitor, never mirrored from status/playback or system/alerts
ok bool Overall device health (HealthMonitor::isFirmwareStable()), independent of playback state
fw_version string Firmware SemVer string
uptime_ms integer Milliseconds since boot
uptime_human string Human-readable uptime, e.g. "5h 23m 45s"
ip_address string Current device IP
gateway string Network gateway IP
rssi integer WiFi signal strength (dBm)
free_heap integer Free heap in bytes

Last Will and Testament (LWT)

Registered on every begin()/reconnect. If the connection drops uncleanly (crash, power loss, network loss), the broker automatically publishes:

{ "device_id": "BSVSPR-26E11J-STD10R-M4SC2Z", "state": "offline", "ok": false }

to status/heartbeat (QoS 1, retained), overwriting the last "online" heartbeat. For intentional disconnects (e.g. mqtt.disable), the firmware explicitly publishes the same payload before disconnecting, since LWT does not fire on a clean disconnect.


vesper/{id}/status/playback

QoS: 1 — Retained: yes — Switch: playback — Trigger: playback state transition only

Published by Player::setStatus() on every transition (not polled). 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.

Payload

Flat — no envelope wrapper.

{
  "action": "playing",
  "time_elapsed": 12,
  "projected_run_time": 45000,
  "pid": "westminster",
  "speed": 400,
  "duration": 120000,
  "started_at": 1790000000,
  "source": "app",
  "ts": 1790000012
}
{ "action": "idle", "time_elapsed": 0, "projected_run_time": 0, "pid": "", "speed": 0, "duration": 0, "started_at": 0, "source": "", "ts": 1790000130 }
Field Type Description
action string playing | paused | stopping | idle — see States
time_elapsed integer Seconds since playback started, as of ts (0 for idle)
projected_run_time integer Projected total run time in ms (0 if not applicable)
pid string Melody being played ("" when idle)
speed integer ms per beat (0 when idle)
duration integer Requested run-time cap in ms — the effective stop timer after mode/legacy field resolution (timed → duration, interval → total_duration, legacy → segment_duration/total_duration). 0 = no cap: a single play ends naturally, infinite runs until stopped. 0 when idle.
started_at integer Unix epoch seconds (UTC) when playback started. 0 when idle or when the board has no valid clock.
source string What started the playback: app (MQTT/WebSocket/HTTP command), rf (RF remote slot), button (UART LCD/button slave board), schedule (reserved — scheduled events don't start playback yet), unknown. "" when idle.
ts integer Unix epoch seconds (UTC) when this message was built. 0 when the board has no valid clock.

Clock source for started_at / ts: the NTP-synced system clock if valid, else the RTC (converted from its stored local time to UTC using the configured offsets), else 0. RTC-less builds (agnus) therefore report 0 until NTP has synced. Always check for 0 before using either.

Stale retained messages. Because the topic is retained, a client may receive a message published long ago. Real elapsed time is now − started_at (when started_at != 0); ts tells you how old the snapshot is. time_elapsed is only correct as of ts.

The WebSocket transport receives the same fields on every transition, wrapped in the legacy broadcast envelope: { "status": "INFO", "type": "playback", "payload": { ...fields above... } }.

States

action Meaning Entered from Leaves to
playing Bells are ringing. idle (play accepted), paused (segment pause over) paused, stopping, idle
paused Between segments of an interval (or legacy continuous_loop) play — bells silent, playback still active. playing playing, idle
stopping The run-time cap (duration) has elapsed; the bells are finishing the current melody loop before stopping (can last up to one full loop, i.e. steps × speed). Still ringing. playing (timer reached duration) idle (loop finished)
idle Nothing playing. any (playback.stop, natural end, overload force-stop) playing

playback.stop during playing/paused/stopping cuts the bells immediately and goes straight to idle — it never passes through stopping. A new playback.play is rejected in every state except idle. The heartbeat's independently-derived state reports idle during stopping.


vesper/{id}/control/reports

QoS: 1 — 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.

Envelope

{ "type": "event_type", "payload": { ... } }

Bell overload event

Published by CommunicationRouter::sendBellOverloadNotification() → publishReport("bell_overload", ...) when per-bell strike load exceeds configured thresholds.

{
  "type": "bell_overload",
  "payload": {
    "bells": [2, 5],
    "loads": [54, 48],
    "severity": "WARNING"
  }
}
Field Type Description
payload.bells array of int 1-indexed bell channel numbers that are overloaded
payload.loads array of int Strike count load per bell channel
payload.severity string WARNING (≥60% load) or CRITICAL (≥90% load)

vesper/{id}/system/alerts

QoS: 1 — Retained: yes, until cleared — Switch: alerts — Trigger: subsystem state change only

Published by HealthMonitor (via CommunicationRouter::publishAlert()) whenever a subsystem transitions between health states. Published once on change; not repeated until the state changes again. Silent if MQTT is not connected, or the alerts switch is off, at the moment of the transition. Retained so a late-connecting console (fleet webserver) immediately sees the last unresolved alert per subsystem.

The server should:

  • Maintain a per-device active alert set (e.g. a dict keyed by subsystem)
  • On receipt: upsert the alert in the set
  • On CLEARED: remove the entry from the set
  • Display the active alert set statically on the device detail page — not as a scrolling log

Alert payload (problem)

{ "subsystem": "FileManager", "state": "WARNING", "msg": "ConfigManager health check failed" }

Cleared payload (recovery)

{ "subsystem": "FileManager", "state": "CLEARED" }
Field Type Description
subsystem string Subsystem name. One of: BellEngine, OutputManager, Player, Communication, TimeKeeper, Telemetry, OTAManager, Networking, ConfigManager, FileManager, System
state string New state: WARNING | CRITICAL | FAILED | CLEARED
msg string Human-readable description. Absent when state is CLEARED.

State meanings

State Meaning
WARNING Subsystem has an issue but device continues to operate
CRITICAL Subsystem failure affects core functionality
FAILED Subsystem is non-functional (equivalent to CRITICAL for critical subsystems)
CLEARED Subsystem has recovered; remove from active alert set

Critical vs non-critical subsystems

Subsystem Critical? Notes
BellEngine yes Core timing — CRITICAL triggers rollback consideration
OutputManager yes Hardware — CRITICAL triggers rollback consideration
Player yes Melody control
ConfigManager no SD card absence maps to WARNING
FileManager no SD card absence maps to WARNING
Communication no MQTT/WS failure
TimeKeeper no RTC sync failure
Telemetry no Strike counting
OTAManager no OTA update subsystem
Networking no WiFi connectivity

A fault-class boot reset also publishes here — subsystem: "System", e.g.:

{ "subsystem": "System", "state": "WARNING", "msg": "Device reset due to fault: TASK_WATCHDOG" }

vesper/{id}/system/info

QoS: 1 — Retained: yes — Switch: info — Trigger: discrete device state event

Published for general device state changes that are not health failures and not quantitative telemetry (see system/metrics for that). Use this topic to update the device detail panel (e.g. boot reason) without polling.

Envelope

{ "type": "event_type", "payload": { ... } }

boot_report

Published once, the first time MQTT connects after boot (guarded, not repeated on reconnect).

{
  "type": "boot_report",
  "payload": {
    "boot_count": 47,
    "reset_reason": "PANIC",
    "is_fault": true,
    "free_heap": 187234,
    "crash": { "task": "TelemetryTask", "pc": 1074111832, "exc_cause": 1, "exc_vaddr": 0 }
  }
}

crash is present only when a coredump was found for the crash that caused this boot — omitted on a clean/expected reset or a fault reset with no coredump (e.g. brownout). A fault-class reset additionally publishes a system/alerts WARNING (see above) — system/info's boot_report is published unconditionally, fault or not.


vesper/{id}/system/logs

QoS: 0 — Retained: no — Switch: logs

Mirrors the serial log stream, respecting both the configured MQTT log level (log.set_mqtt, 0–5) and this topic's own ON/OFF switch independently — the switch can silence the whole channel without touching the configured level. See Logging.

{ "level": "WARNING", "subsystem": "BellEngine", "message": "...", "timestamp": 12345 }

timestamp is millis() (ms since boot), not wall-clock time.


vesper/{id}/system/metrics

QoS: 0 — Retained: no — Switch: metrics — Interval: 5 minutes

Structured telemetry for fleet-health graphing — not consumed by the phone app. Published by CommunicationRouter::reportDiagnosticsIfDue().

{
  "cpu_temp": { "avg": 47.1, "min": 44.8, "max": 52.8, "samples": 20 },
  "wifi_reconnects": { "lifetime_count": 2, "last_reason": "AUTH_EXPIRE", "last_at_uptime_ms": 3600000 },
  "ota": { "current_version": "2.2.0", "update_available": false, "last_check_uptime_ms": 180000, "last_error": "NONE" },
  "stack_high_water": { "TelemetryTask": 1024, "HealthMonitor": 890 },
  "bell_strikes": { "0": 1234, "1": 567 },
  "bell_loads": { "0": 12, "1": 0 },
  "cooling_active": false
}
Field Type Description
cpu_temp object Min/max/avg CPU die temperature (°C) since the last report
wifi_reconnects object Lifetime-this-boot reconnect count, last disconnect reason/uptime
ota object Current/available version, update-available flag, last check time, last error
stack_high_water object Bytes free per registered task (low-water mark)
bell_strikes object Cumulative strike count per bell channel (0–15)
bell_loads object Current heat-load accumulator per bell channel
cooling_active bool True if any bell still has residual heat

vesper/{id}/control/command and vesper/{id}/control/ack

QoS: 1 — Retained: no — Switch: command

control/command is read-only from the board's perspective — the board only ever receives here. control/ack is strictly reply-only: every message on it answers a specific request (including pong), and no unsolicited event is ever published there. Both support an optional req_id field for correlation — see vesper_mqtt_topic_spec_v2.md.

Command (inbound)

{ "v": 2, "cmd": "playback.stop", "req_id": "abc123" }

Reply (outbound)

{ "status": "SUCCESS", "type": "playback", "req_id": "abc123", "message": "Playback command executed" }

Reply envelope: status (SUCCESS/ERROR), type, optional req_id, and either message (string — text replies and every error) or data (object — structured replies). There is no payload key. req_id only appears in the reply if the request included one. See api-reference.md for the full envelope rules.

CommandBus::broadcast() would also publish here (same envelope, status: "INFO", no req_id), but nothing in the firmware calls it today — purpose-specific events (playback, alerts, reports, metrics) publish directly to their own topics.

Malformed input

Invalid JSON or a missing cmd field gets an ERROR reply on control/ack (type: "parse_error") instead of being silently dropped:

{ "status": "ERROR", "type": "parse_error", "message": "Invalid JSON: IncompleteInput" }
{ "status": "ERROR", "type": "parse_error", "message": "Missing required field: cmd" }

Server subscription pattern

vesper/+/status/heartbeat   → update last_seen + state/ok, no logging (unless state:"offline" from LWT)
vesper/+/status/playback    → update device detail panel's playback state
vesper/+/control/reports    → surface immediately — critical, time-sensitive (e.g. bell_overload)
vesper/+/system/alerts      → upsert/remove active alert set per device
vesper/+/system/info        → update device state panel (boot_report, etc.)
vesper/+/system/logs        → remote log viewer / archival
vesper/+/system/metrics     → fleet-health graphing / time-series storage
vesper/+/control/ack        → command responses only (phone app / whoever issued the command)

Migration from v1 topics

See vesper_mqtt_topic_spec_v2.md for the full old→new topic mapping. Summary: control→control/command, data→control/ack (+ new control/reports and status/playback split out), status/alerts→system/alerts, status/info→system/info (diagnostics moved to new system/metrics), plus new system/logs.


Removed events

Event Was published to Removed in Reason
ding (bell fired) vesper/{id}/data (WebSocket only) Firmware v155+ Unstable under load; no active consumers
(entire v1 topic set: control, data, status/alerts, status/info) — v2.2.0 Replaced wholesale by the v2 topic spec — see F-062 in feature-catalog.md