Files
project-vesper/docs/reference/api-reference.md
T
bonaminandClaude Sonnet 5 391ecb63fc feat(MQTT): rebuild topic spec to v2 (F-062)
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>
2026-09-21 10:48:36 +03:00

1105 lines
28 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Vesper Firmware — API Reference (v2)
> Command reference for the Vesper Bell Automation System.
> Firmware v2 command bus architecture — all transports, all handlers.
> Last updated: 2026-09-21 (MQTT topic spec v2 — see F-062 in feature-catalog.md)
---
## Overview
### Message Envelope
Every command sent to Vesper uses this JSON envelope:
```json
{
"v": 2,
"cmd": "namespace.command",
"req_id": "abc123",
"contents": { ... }
}
```
| Field | Type | Notes |
|---|---|---|
| `v` | int | Protocol version. `2` = current. Omit or set `1` for legacy (LegacyAdapter runs). |
| `cmd` | string | `namespace.command` format (e.g. `relay.set_durations`). |
| `req_id` | string | Optional. Echoed back on the reply for correlation when a caller shares one channel across multiple requests/senders (e.g. MQTT `control/command`). Omit for a reply with no `req_id` field — fully backward compatible. |
| `contents` | object | Command payload. May be omitted if command takes no fields. |
### Response Envelope
```json
{
"status": "SUCCESS" | "ERROR",
"type": "command_name",
"req_id": "abc123",
"payload": { ... }
}
```
`payload` is command-specific. On error, `payload` typically contains a `"message"` string. `req_id` is present only if the request included one.
---
## Transports
MQTT uses the v2 topic set — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md) for the full table, per-topic ON/OFF switches, `req_id` correlation, and LWT. WebSocket, HTTP, and UART are unchanged by the v2 MQTT rebuild.
| Transport | Address | Direction | Notes |
|---|---|---|---|
| MQTT | `vesper/{device_id}/control/command` | Inbound commands | Read-only from the board's perspective. Replies go to `control/ack`. |
| MQTT | `vesper/{device_id}/control/ack` | Outbound replies | Strictly request/response — nothing unsolicited |
| MQTT | `vesper/{device_id}/control/reports` | Outbound, critical unsolicited events | e.g. bell overload — not retained |
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s + LWT; server updates last_seen |
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 1 | Playback transitions only |
| MQTT | `vesper/{device_id}/system/alerts` | Outbound, retained until cleared, QoS 1 | Subsystem state-change events (published on change only) |
| MQTT | `vesper/{device_id}/system/info` | Outbound, retained, QoS 1 | Discrete device state events (boot report, etc.) |
| MQTT | `vesper/{device_id}/system/logs` | Outbound, QoS 0 | Mirrors serial log stream |
| MQTT | `vesper/{device_id}/system/metrics` | Outbound, QoS 0 | Structured telemetry every 5 min — fleet-health graphing |
| WebSocket | `ws://{device_ip}/ws` | Bidirectional | Requires `identify` on connect |
| HTTP | `http://{device_ip}/...` | REST | Web console endpoints |
| UART | Hardware serial | Bidirectional | Restricted — whitelist only (see below) |
| UDP | Port 32101 | Discovery broadcast | Passive — device announces itself |
### UART Whitelist
Only the following commands are accepted over UART (LCD/button slave board). All others are silently dropped.
```
ping
playback
clock.pause
clock.resume
system.get_time
```
### WebSocket — Client Identification
WebSocket clients must send `identify` immediately after connecting, or they will not receive targeted responses:
```json
{ "v": 2, "cmd": "identify", "contents": { "device_type": "master" } }
```
`device_type`: `"master"` (app/console) or `"secondary"` (slave board).
---
## Command Reference
---
### `ping`
| | |
|---|---|
| Handler | SystemHandler |
| Transports | All |
| Contents | *(none)* |
| Returns | `{ "status": "SUCCESS", "type": "pong" }` |
```json
{ "v": 2, "cmd": "ping" }
```
---
### `identify`
| | |
|---|---|
| Handler | SystemHandler |
| Transports | WebSocket only |
| Contents | `device_type` (required) |
```json
{ "v": 2, "cmd": "identify", "contents": { "device_type": "master" } }
```
---
### `playback`
| | |
|---|---|
| Handler | PlaybackHandler |
| Transports | All |
| Contents | `action` (required) + melody fields |
`action` values: `"play"`, `"stop"`, `"pause"`, `"unpause"`
```json
{ "v": 2, "cmd": "playback", "contents": { "action": "play", "pid": "ormilia_1_8", "speed": 200, "total_duration": 60000, "note_assignments": [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0] } }
{ "v": 2, "cmd": "playback", "contents": { "action": "stop" } }
```
| Field | Type | Required | Notes |
|---|---|---|---|
| `action` | string | yes | `"play"` or `"stop"` |
| `pid` | string | yes (play) | Playback ID. Checked against built-in library first, then SD card, then downloaded via `download_url`. |
| `download_url` | string | no | URL to download the melody binary if not found locally. |
| `speed` | int | no | ms per beat. Default 500. |
| `total_duration` | int | no | Total playback ms. `0` = play to natural end. |
| `segment_duration` | int | no | Duration per loop segment (ms). Used with `continuous_loop`. |
| `pause_duration` | int | no | Pause between segments (ms). |
| `continuous_loop` | bool | no | Loop with pause/resume segments. |
| `note_assignments` | int[16] | no | Bell mapping (0-indexed note → 1-indexed output, 0 = unused). |
---
## Relay Namespace — `RelayHandler`
---
### `relay.set_durations`
Set strike duration (ms) for one or more bell channels. Partial updates accepted — omitted channels are unchanged.
| | |
|---|---|
| Required | At least one bell entry |
| Contents | `{ "bells": { "0": 95, "2": 110 } }` |
```json
{
"v": 2,
"cmd": "relay.set_durations",
"contents": { "bells": { "0": 95, "1": 100, "2": 110 } }
}
```
---
### `relay.set_outputs`
Map bell channels to physical relay outputs. Partial updates accepted.
| | |
|---|---|
| Required | At least one bell entry |
| Contents | `{ "bells": { "0": 2, "1": 3 } }` |
```json
{
"v": 2,
"cmd": "relay.set_outputs",
"contents": { "bells": { "0": 2, "1": 3, "2": 4 } }
}
```
---
### `relay.get_config`
Read current bell durations and output assignments.
| | |
|---|---|
| Required | *(none)* |
| Returns | `{ "durations": { "0": 95, ... }, "outputs": { "0": 2, ... } }` |
```json
{ "v": 2, "cmd": "relay.get_config" }
```
---
### `relay.test_output`
Fire a specific relay for a caller-specified duration. Safety-gated: Player must be stopped.
| | |
|---|---|
| Required | `output` (int), `duration_ms` (int) |
| Notes | Both fields required — no defaults. Typical range: 85–140 ms. |
```json
{
"v": 2,
"cmd": "relay.test_output",
"contents": { "output": 2, "duration_ms": 95 }
}
```
---
## Clock Namespace — `ClockHandler`
---
### `clock.set_outputs`
Set which relay outputs the clock strikes use.
| | |
|---|---|
| Required | At least one of `c1`, `c2` |
| Contents | `{ "c1": 4, "c2": 5 }` — partial OK |
---
### `clock.set_timings`
Set clock strike timing configuration. Partial updates accepted.
---
### `clock.set_alerts`
Configure hourly/quarter alert behavior. Partial updates accepted.
---
### `clock.set_backlight`
Configure backlight behavior. Partial updates accepted.
---
### `clock.set_silence`
Configure silence period (quiet hours). Partial updates accepted.
---
### `clock.set_time`
Set the RTC time.
| | |
|---|---|
| Required | `timestamp` (Unix epoch, int) |
| Optional | `timezone_offset` (int, seconds), `dst_offset` (int, seconds) |
```json
{
"v": 2,
"cmd": "clock.set_time",
"contents": { "timestamp": 1740000000, "timezone_offset": 7200 }
}
```
---
### `clock.set_face`
Set the physical analog clock face position.
| | |
|---|---|
| Required | `hour` (int), `minute` (int) |
```json
{ "v": 2, "cmd": "clock.set_face", "contents": { "hour": 10, "minute": 10 } }
```
---
### `clock.set_timezone`
Set timezone independently of RTC time.
| | |
|---|---|
| Required | `gmt_offset_sec` (int) |
| Optional | `dst_offset_sec` (int), `timezone_name` (string) |
```json
{
"v": 2,
"cmd": "clock.set_timezone",
"contents": { "gmt_offset_sec": 7200, "dst_offset_sec": 3600, "timezone_name": "Europe/Athens" }
}
```
---
### `clock.get_timezone`
Read current timezone settings.
| | |
|---|---|
| Returns | `{ "gmt_offset_sec": 7200, "dst_offset_sec": 3600, "timezone_name": "..." }` |
---
### `clock.sync_ntp`
Force an immediate NTP time sync.
| | |
|---|---|
| Required | *(none)* |
---
### `clock.enable` / `clock.disable`
Enable or disable clock strike output.
```json
{ "v": 2, "cmd": "clock.enable" }
{ "v": 2, "cmd": "clock.disable" }
```
---
### `clock.pause` / `clock.resume`
Pause or resume clock updates.
```json
{ "v": 2, "cmd": "clock.pause" }
{ "v": 2, "cmd": "clock.resume" }
```
---
### `clock.get_face`
Read current analog clock face position.
| | |
|---|---|
| Returns | `{ "clock_hour", "clock_minute", "last_sync_time", "next_output_is_c1" }` |
---
### `clock.get_config`
Read full clock configuration (outputs, timings, alerts, backlight, silence, enabled state).
---
## System Namespace — `SystemHandler`
---
### `system.status`
Get current device status: player state, strike counters, projected run time.
```json
{ "v": 2, "cmd": "system.status" }
```
---
### `system.get_time`
Get current RTC time.
| | |
|---|---|
| Returns | `{ "local_timestamp", "utc_timestamp", "year", "month", "day", "hour", "minute", "second", "rtc_available" }` |
```json
{ "v": 2, "cmd": "system.get_time" }
```
---
### `system.get_settings`
Get full ConfigManager JSON dump (all saved settings).
```json
{ "v": 2, "cmd": "system.get_settings" }
```
---
### `system.get_device_info`
Get device identity and runtime stats.
| | |
|---|---|
| Returns | `{ "uid", "hw_type", "hw_version", "fw_version", "uptime_ms", "free_heap", "min_free_heap" }` |
```json
{ "v": 2, "cmd": "system.get_device_info" }
```
---
### `system.health`
Get full HealthMonitor report — all subsystem states, warnings, critical failures.
```json
{ "v": 2, "cmd": "system.health" }
```
---
### `system.factory_reset`
Reset all settings to factory defaults.
> **Warning:** Non-reversible. All saved configuration is wiped.
```json
{ "v": 2, "cmd": "system.factory_reset" }
```
---
### `system.restart`
Reboot the device. Response is sent before reboot (2s delay).
```json
{ "v": 2, "cmd": "system.restart" }
```
---
### `system.set_identity`
Overwrite the device's factory-set identity (`serial`, `hw_family`, `hw_revision`) in NVS and reboot to apply it. Intended for sysadmin use only — e.g. reassigning a serial after a board swap, or correcting a mis-provisioned unit — via the backend console, which is responsible for updating its own device record (including re-deriving the MQTT password from the new serial) in the same operation. Firmware does not touch the backend record itself.
> **Warning:** Non-reversible from the device's perspective, and dangerous if the backend device record isn't updated to match — a serial mismatch will break MQTT auth (password is derived from serial), and a wrong `hw_family`/`hw_revision` can pull an OTA build for the wrong hardware. Device restarts 2s after a successful response to apply the new identity.
| | |
|---|---|
| Handler | SystemHandler |
| Transports | MQTT only |
| Contents | `serial` (required), `hw_family` (required), `hw_revision` (required) |
```json
{ "v": 2, "cmd": "system.set_identity", "contents": { "serial": "PV000000000001", "hw_family": "VS", "hw_revision": "01" } }
```
**Errors:**
| Message | Condition |
|---|---|
| `system.set_identity is only available via MQTT` | Sent over WebSocket, HTTP, or UART |
| `Missing required fields: serial, hw_family, hw_revision (all required)` | One or more fields absent or not a string |
| `serial, hw_family and hw_revision must be non-empty` | One or more fields present but empty |
| `Failed to persist new identity to NVS — device identity unchanged` | NVS write/commit failed |
---
## Firmware Namespace — `FirmwareHandler`
---
### `firmware.status`
Get firmware validation state.
| | |
|---|---|
| Returns | `{ "validation_state", "current_version", "is_testing", "is_valid", "boot_count", "build_date", "ota_channel", "startup_retry_count", "max_startup_retries", "runtime_failure_count", "max_runtime_failures", "backup_version", "backup_is_valid", "can_commit", "can_rollback", "runtime_timeout_ms"? }` |
`startup_retry_count`, `runtime_failure_count`, and the backup partition fields are the OTA rollback safety-net's internal counters — previously only visible via serial/SD log output, now queryable remotely. Useful for diagnosing why a device rolled back an update. `runtime_timeout_ms` is only present while `is_testing` is true.
```json
{ "v": 2, "cmd": "firmware.status" }
```
---
### `firmware.commit`
Commit the current firmware as permanent (marks OTA slot as valid).
```json
{ "v": 2, "cmd": "firmware.commit" }
```
---
### `firmware.rollback`
Roll back to the previous firmware. Device reboots.
```json
{ "v": 2, "cmd": "firmware.rollback" }
```
---
## OTA Namespace — `FirmwareHandler`
---
### `ota.status`
Get OTA update status.
| | |
|---|---|
| Returns | `{ "current_version", "available_version", "channel", "update_available", "last_check", "progress" }` |
```json
{ "v": 2, "cmd": "ota.status" }
```
---
### `ota.check`
Check for available updates.
| | |
|---|---|
| Optional | `channel` (string, default `"stable"`) |
```json
{ "v": 2, "cmd": "ota.check", "contents": { "channel": "beta" } }
```
---
### `ota.update`
Trigger OTA update from VPS. Device may reboot.
| | |
|---|---|
| Optional | `channel` (string, default `"stable"`) |
```json
{ "v": 2, "cmd": "ota.update", "contents": { "channel": "stable" } }
```
---
### `ota.custom`
Flash firmware from a custom URL.
| | |
|---|---|
| Required | `firmware_url` (string) |
| Optional | `checksum` (string), `file_size` (int), `version` (string) |
```json
{
"v": 2,
"cmd": "ota.custom",
"contents": {
"firmware_url": "http://example.com/firmware.bin",
"checksum": "abc123",
"version": "142"
}
}
```
---
## Network Namespace — `NetworkHandler`
---
### `network.info`
Get IP/gateway/DNS.
| | |
|---|---|
| Returns | `{ "ip", "gateway", "dns" }` |
```json
{ "v": 2, "cmd": "network.info" }
```
---
### `network.status`
Get full connection state.
| | |
|---|---|
| Returns | `{ "connected", "state", "type", "ip", "rssi", "ap_mode" }` |
```json
{ "v": 2, "cmd": "network.status" }
```
---
### `network.set_config`
Update network configuration. Partial updates accepted. Returns `restart_required` flag.
| | |
|---|---|
| Required | At least one field |
| Optional | `hostname`, `useStaticIP`, `ip`, `gateway`, `subnet`, `dns1`, `dns2` |
| Notes | Static IP requires `ip` + `gateway` + `subnet` together |
```json
{
"v": 2,
"cmd": "network.set_config",
"contents": { "hostname": "vesper-lab", "useStaticIP": false }
}
```
---
## Files Namespace — `FileHandler`
---
### `files.list`
List melody files on the SD card.
| | |
|---|---|
| Returns | Array of SD card melody file objects |
```json
{ "v": 2, "cmd": "files.list" }
```
---
### `files.list_builtin`
List all built-in melodies compiled into the firmware.
| | |
|---|---|
| Returns | `[{ "name": "...", "pid": "..." }, ...]` |
```json
{ "v": 2, "cmd": "files.list_builtin" }
```
---
### `files.download`
Download a melody from the server to the SD card.
| | |
|---|---|
| Required | `melodys_uid` (string) |
```json
{ "v": 2, "cmd": "files.download", "contents": { "melodys_uid": "ABC123" } }
```
---
### `files.delete`
Delete a melody from the SD card.
| | |
|---|---|
| Required | `name` (string) |
```json
{ "v": 2, "cmd": "files.delete", "contents": { "name": "westminster.mel" } }
```
---
## Log Namespace — `LoggingHandler`
Set log verbosity per output channel. Level 0 = off, 5 = verbose.
| Level | Meaning |
|---|---|
| 0 | None |
| 1 | Error |
| 2 | Warning |
| 3 | Info |
| 4 | Debug |
| 5 | Verbose |
### `log.set_serial`
```json
{ "v": 2, "cmd": "log.set_serial", "contents": { "level": 0 } }
```
### `log.set_sd`
```json
{ "v": 2, "cmd": "log.set_sd", "contents": { "level": 0 } }
```
### `log.set_mqtt`
```json
{ "v": 2, "cmd": "log.set_mqtt", "contents": { "level": 0 } }
```
---
### `logs.list`
List day-rotated SD log files (`/logs/YYYY-MM-DD.log`). Requires an SD card — returns an error on boards without one.
| | |
|---|---|
| Returns | `{ "files": [{ "name": "2026-07-14.log", "size": 1234 }, ...] }` |
```json
{ "v": 2, "cmd": "logs.list" }
```
---
### `logs.download`
Read a bounded chunk of a log file. Responses are capped at 4096 bytes regardless of file size — callers loop, feeding `next_offset` back in as `offset`, until `eof` is `true`. Requires an SD card.
| | |
|---|---|
| Required | `file` (string) — bare filename as returned by `logs.list`, no path separators |
| Optional | `offset` (int, default `0`) |
| Returns | `{ "file", "data", "next_offset", "eof" }` |
```json
{ "v": 2, "cmd": "logs.download", "contents": { "file": "2026-07-14.log", "offset": 0 } }
```
Loop example: keep calling with `contents.offset = <previous next_offset>` until the response has `"eof": true`.
---
## RF Remote Namespace — `RFRemoteHandler`
> Available on hardware variants with `HAS_RF=1` (e.g. Vesper, Vesper+).
> All commands are silently rejected on variants without RF hardware.
The RF subsystem uses a **slot model**: up to 16 independent slots, each binding one RF trigger code to a complete playback action. Slots are blank by default — nothing is pre-seeded. Program them over MQTT after flashing.
### Slot object
| Field | Type | Required | Notes |
|---|---|---|---|
| `slot` | int | yes | Slot index, 0–15 |
| `rf_code` | uint32 | yes | Raw 433 MHz code that triggers this slot. Must be non-zero. |
| `pid` | string | yes (play) | Playback ID. Checked against built-in library first, then SD card. Use `files.list_builtin` or `files.list` for valid PIDs. |
| `speed` | int | no | ms per beat. Default 500. |
| `duration` | int | no | Total playback ms. Default 30000. `0` = play to natural end. |
| `note_assignments` | int[16] | no | Bell mapping array (0-indexed note → 1-indexed bell output, 0 = unused). Default all zeros. |
| `is_stop` | bool | no | If `true`, receiving this code calls force-stop (single press, no long-press required). `pid`/`speed`/`duration` ignored. Default `false`. |
**`note_assignments` example:** A melody written for 6 bells played on 3 physical bells, doubled:
```json
"note_assignments": [1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
```
---
### `rf.set_slot`
Program one slot, or multiple slots in a single command.
| | |
|---|---|
| Handler | RFRemoteHandler |
| Transports | All |
| Persists | NVS namespace `rf` (survives reboot) |
**Single slot:**
```json
{
"v": 2,
"cmd": "rf.set_slot",
"contents": {
"slot": 0,
"rf_code": 9274392,
"pid": "vesper_fst_1_4",
"speed": 500,
"duration": 60000,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"is_stop": false
}
}
```
**Multiple slots (batch):**
```json
{
"v": 2,
"cmd": "rf.set_slot",
"contents": {
"slots": [
{ "slot": 0, "rf_code": 9274392, "pid": "vesper_fst_1_4", "speed": 500, "duration": 60000, "note_assignments": [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0] },
{ "slot": 1, "rf_code": 9274388, "pid": "doxology_1_4", "speed": 500, "duration": 60000 },
{ "slot": 7, "rf_code": 9274385, "is_stop": true }
]
}
}
```
Returns:
```json
{ "status": "SUCCESS", "type": "rf.set_slot", "payload": "3 slot(s) programmed" }
```
---
### `rf.clear_slot`
Clear a single slot, or all slots.
| | |
|---|---|
| Required | `slot` — int (0–15) or string `"all"` |
```json
{ "v": 2, "cmd": "rf.clear_slot", "contents": { "slot": 3 } }
{ "v": 2, "cmd": "rf.clear_slot", "contents": { "slot": "all" } }
```
---
### `rf.get_slots`
Return the full slot table (all 16 slots).
| | |
|---|---|
| Contents | *(none)* |
| Returns | `{ "enabled": bool, "slots": [ { slot object } × 16 ] }` |
Each entry includes an `"empty": true/false` field. Empty slots have `rf_code: 0` and all other fields at their defaults.
```json
{ "v": 2, "cmd": "rf.get_slots" }
```
Example response excerpt:
```json
{
"status": "SUCCESS",
"type": "rf.get_slots",
"data": {
"enabled": true,
"slots": [
{
"slot": 0,
"empty": false,
"rf_code": 9274392,
"pid": "vesper_fst_1_4",
"speed": 500,
"duration": 60000,
"is_stop": false,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
{ "slot": 1, "empty": true, "rf_code": 0, ... },
...
]
}
}
```
---
### `rf.enable`
Enable or disable RF reception at runtime.
| | |
|---|---|
| Required | `enabled` (bool) |
```json
{ "v": 2, "cmd": "rf.enable", "contents": { "enabled": true } }
{ "v": 2, "cmd": "rf.enable", "contents": { "enabled": false } }
```
---
## MQTT Namespace — `MQTTHandler`
### `mqtt.enable` / `mqtt.disable`
Enable or disable MQTT connectivity (master switch — disconnects/reconnects the broker entirely). `mqtt.disable` publishes a graceful offline heartbeat before disconnecting.
```json
{ "v": 2, "cmd": "mqtt.enable" }
{ "v": 2, "cmd": "mqtt.disable" }
```
### `mqtt.get_config`
Returns broker connection settings.
| | |
|---|---|
| Returns | `{ "enabled": true, "host": "72.61.191.197", "port": 1883, "user": "...", "use_ssl": false }` |
```json
{ "v": 2, "cmd": "mqtt.get_config" }
```
### `mqtt.get_topics`
Returns the current state of all 8 per-topic ON/OFF publish switches. See [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md#per-topic-onoff-switches).
| | |
|---|---|
| Returns | `{ "command": true, "heartbeat": true, "playback": true, "reports": true, "alerts": true, "info": true, "logs": true, "metrics": true }` |
```json
{ "v": 2, "cmd": "mqtt.get_topics" }
```
### `mqtt.set_topics`
Partial update of the per-topic ON/OFF switches — only send the fields you want to change. These only take effect while `mqtt.enable` (the master switch) is on. `command` gates both `control/command` (subscription) and `control/ack` (replies) together, and applies live without a reconnect.
| | |
|---|---|
| Optional | Any of `command`, `heartbeat`, `playback`, `reports`, `alerts`, `info`, `logs`, `metrics` (bool) — at least one required |
```json
{ "v": 2, "cmd": "mqtt.set_topics", "contents": { "heartbeat": true, "metrics": false } }
```
| Error | Condition |
|---|---|
| `"No recognised topic fields in contents (command, heartbeat, playback, reports, alerts, info, logs, metrics)"` | No valid boolean fields present |
| `"Topic switches changed but failed to save to SD"` | Applied in RAM but persistence failed |
---
## Telemetry Namespace — `TelemetryHandler`
---
### `telemetry.get_strikes`
Get strike counts per bell channel.
| | |
|---|---|
| Returns | `{ "strikes": { "0": 1234, "1": 567, ... } }` |
```json
{ "v": 2, "cmd": "telemetry.get_strikes" }
```
---
### `telemetry.reset_strikes`
Reset strike counters. Omit `bell` to reset all channels; include it to reset one.
| | |
|---|---|
| Optional | `bell` (int) — channel index |
```json
{ "v": 2, "cmd": "telemetry.reset_strikes" }
{ "v": 2, "cmd": "telemetry.reset_strikes", "contents": { "bell": 2 } }
```
---
### `telemetry.get_loads`
Get heat load per bell channel, cooling status, and overload flags.
| | |
|---|---|
| Returns | `{ "loads": { "0": 42.5, ... }, "cooling_active": false, "overloaded": [2, 5] }` |
```json
{ "v": 2, "cmd": "telemetry.get_loads" }
```
---
## MQTT Events (Unsolicited)
These messages are published by the device without a request, on the v2 topic set (`control/command`+`control/ack`, `control/reports`, `status/heartbeat`, `status/playback`, `system/alerts`, `system/info`, `system/logs`, `system/metrics`). Full field-level reference, per-topic switches, LWT, and `req_id` correlation: [mqtt-events.md](mqtt-events.md) and [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_topic_spec_v2.md).
| Topic | When | QoS | Retained | Switch |
|---|---|---|---|---|
| `vesper/{id}/status/heartbeat` | Every 30s (+ LWT on unclean disconnect) | 1 | yes | `heartbeat` |
| `vesper/{id}/status/playback` | On playback transition | 1 | yes | `playback` |
| `vesper/{id}/control/reports` | Critical unsolicited events (e.g. bell overload) | 1 | no | `reports` |
| `vesper/{id}/system/alerts` | On subsystem state change only | 1 | yes, until cleared | `alerts` |
| `vesper/{id}/system/info` | On discrete device state events (e.g. boot report) | 1 | yes | `info` |
| `vesper/{id}/system/logs` | Mirrors serial log stream | 0 | no | `logs` |
| `vesper/{id}/system/metrics` | Every 5 min — CPU temp, WiFi/OTA state, bell heat | 0 | no | `metrics` |
| `vesper/{id}/control/ack` | Reply to every command (strictly request/response) | 1 | no | `command` |
---
## Legacy Compatibility (v1)
If a client sends `"v": 1` (or omits `v`), the `LegacyAdapter` translates the old `cmd` + `action` pair to a v2 command before dispatch. No code changes needed on the client side during transition.
| v1 `cmd` | v1 `action` | v2 `cmd` |
|---|---|---|
| `ping` | — | `ping` |
| `identify` | — | `identify` |
| `playback` | — | `playback` |
| `file_manager` | `list_melodies` | `files.list` |
| `file_manager` | `download_melody` | `files.download` |
| `file_manager` | `delete_melody` | `files.delete` |
| `relay_setup` | `set_timings` | `relay.set_durations` |
| `relay_setup` | `set_outputs` | `relay.set_outputs` |
| `clock_setup` | `set_outputs` | `clock.set_outputs` |
| `clock_setup` | `set_timings` | `clock.set_timings` |
| `clock_setup` | `set_alerts` | `clock.set_alerts` |
| `clock_setup` | `set_backlight` | `clock.set_backlight` |
| `clock_setup` | `set_silence` | `clock.set_silence` |
| `clock_setup` | `set_rtc_time` | `clock.set_time` |
| `clock_setup` | `set_physical_clock_time` | `clock.set_face` |
| `clock_setup` | `pause_clock_updates` | `clock.pause` |
| `clock_setup` | `resume_clock_updates` | `clock.resume` |
| `clock_setup` | `set_enabled` + `enabled=true` | `clock.enable` |
| `clock_setup` | `set_enabled` + `enabled=false` | `clock.disable` |
| `system_info` | `report_status` | `system.status` |
| `system_info` | `get_device_time` | `system.get_time` |
| `system_info` | `get_clock_time` | `clock.get_face` |
| `system_info` | `get_firmware_status` | `firmware.status` |
| `system_info` | `network_info` | `network.info` |
| `system_info` | `get_full_settings` | `system.get_settings` |
| `system_info` | `sync_time_to_lcd` | `system.get_time` *(LCD now uses request/response)* |
| `system` | `status` | `system.status` |
| `system` | `reset_defaults` | `system.factory_reset` |
| `system` | `commit_firmware` | `firmware.commit` |
| `system` | `rollback_firmware` | `firmware.rollback` |
| `system` | `get_firmware_status` | `firmware.status` |
| `system` | `set_network_config` | `network.set_config` |
| `system` | `set_serial_log_level` | `log.set_serial` |
| `system` | `set_sd_log_level` | `log.set_sd` |
| `system` | `set_mqtt_log_level` | `log.set_mqtt` |
| `system` | `set_mqtt_enabled` + `enabled=true` | `mqtt.enable` |
| `system` | `set_mqtt_enabled` + `enabled=false` | `mqtt.disable` |
| `system` | `restart` | `system.restart` |
| `system` | `reboot` | `system.restart` |
| `system` | `force_update` | `ota.update` |
| `system` | `custom_update` | `ota.custom` |
---
## Quick Reference
| Namespace | Commands |
|---|---|
| *(root)* | `ping`, `identify`, `playback` |
| `relay` | `set_durations`, `set_outputs`, `get_config`, `test_output` |
| `clock` | `set_outputs`, `set_timings`, `set_alerts`, `set_backlight`, `set_silence`, `set_time`, `set_face`, `set_timezone`, `get_timezone`, `sync_ntp`, `enable`, `disable`, `pause`, `resume`, `get_face`, `get_config` |
| `system` | `status`, `get_time`, `get_settings`, `get_device_info`, `health`, `factory_reset`, `restart` |
| `firmware` | `status`, `commit`, `rollback` |
| `ota` | `status`, `check`, `update`, `custom` |
| `network` | `info`, `status`, `set_config` |
| `files` | `list`, `list_builtin`, `download`, `delete` |
| `log` | `set_serial`, `set_sd`, `set_mqtt` |
| `mqtt` | `enable`, `disable` |
| `telemetry` | `get_strikes`, `reset_strikes`, `get_loads` |
| `rf` | `set_slot`, `clear_slot`, `get_slots`, `enable` *(HAS_RF variants only)* |