Files
project-vesper/docs/reference/api-reference.md
T
bonaminandClaude Sonnet 4.6 d4bd990e53 feat: semver versioning, FastAPI OTA integration, health alerts via MQTT
- Version.hpp: extract FW_VERSION from main.cpp into shared header
- OTAManager: replace uint16_t version with SemVer struct; update API URLs
  to new FastAPI backend (/api/firmware/{hw_type}/{channel}/latest);
  add postDownloadTelemetry() and postFlashTelemetry() for fleet visibility
- ConfigManager: remove fwVersion from DeviceConfig (always read from
  FW_VERSION constant); saveDeviceConfig/loadDeviceConfig are now no-ops;
  fallbackServerUrl replaced with fallbackServerUrls[2] array
- HealthMonitor: add AlertCallback + setAlertCallback() firing on state
  transitions (including CLEARED on recovery)
- CommunicationRouter: wire HealthMonitor alert callback on begin();
  add publishAlert() and publishInfo() for MQTT status topics
- MQTTDriver: add _alertsTopic + _infoTopic; add publishDirect() for
  absolute topic publishing; migrate heartbeat to JsonDocument
- ResponseBuilder, ClientManager, BellEngine: StaticJsonDocument /
  DynamicJsonDocument → JsonDocument; remove dead notifyBellsFired()
- docs: reorganise into architecture/, dev/, features/, reference/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 22:15:27 +02:00

873 lines
18 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-03-01
---
## Overview
### Message Envelope
Every command sent to Vesper uses this JSON envelope:
```json
{
"v": 2,
"cmd": "namespace.command",
"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`). |
| `contents` | object | Command payload. May be omitted if command takes no fields. |
### Response Envelope
```json
{
"status": "SUCCESS" | "ERROR",
"type": "command_name",
"payload": { ... }
}
```
`payload` is command-specific. On error, `payload` typically contains a `"message"` string.
---
## Transports
| Transport | Address | Direction | Notes |
|---|---|---|---|
| MQTT | `vesper/{device_id}/control` | Inbound commands | Responses go to `vesper/{device_id}/data` |
| MQTT | `vesper/{device_id}/data` | Outbound responses + events | Command replies and bell overload notifications |
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s; server updates last_seen |
| MQTT | `vesper/{device_id}/status/alerts` | Outbound, QoS 1 | Subsystem state-change events (published on change only) |
| MQTT | `vesper/{device_id}/status/info` | Outbound, QoS 0 | General device state events (playback, reboot reason, etc.) |
| 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", "melody_uid": "ABC123" } }
{ "v": 2, "cmd": "playback", "contents": { "action": "stop" } }
```
---
## 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" }
```
---
## Firmware Namespace — `FirmwareHandler`
---
### `firmware.status`
Get firmware validation state.
| | |
|---|---|
| Returns | `{ "validation_state", "version", "boot_count", "can_commit", "can_rollback" }` |
```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": "...", "uid": "..." }, ...]` |
```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": 3 } }
```
### `log.set_sd`
```json
{ "v": 2, "cmd": "log.set_sd", "contents": { "level": 2 } }
```
### `log.set_mqtt`
```json
{ "v": 2, "cmd": "log.set_mqtt", "contents": { "level": 1 } }
```
---
## MQTT Namespace — `MQTTHandler`
### `mqtt.enable` / `mqtt.disable`
Enable or disable MQTT connectivity.
```json
{ "v": 2, "cmd": "mqtt.enable" }
{ "v": 2, "cmd": "mqtt.disable" }
```
---
## 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. See [mqtt-events.md](mqtt-events.md) for the full AsyncAPI-compatible reference.
| Topic | When | QoS | Retained | Format |
|---|---|---|---|---|
| `vesper/{id}/status/heartbeat` | Every 30s | 1 | yes | Heartbeat envelope |
| `vesper/{id}/status/alerts` | On subsystem state change only | 1 | no | Alert envelope |
| `vesper/{id}/status/info` | On device state change | 0 | no | Info envelope |
| `vesper/{id}/data` | Any command response / bell overload | 0 | no | Standard response envelope |
### Heartbeat Payload
```json
{
"status": "INFO",
"type": "heartbeat",
"payload": {
"device_id": "PV-26B18-VS01R-X7KQA",
"firmware_version": "142",
"timestamp": "Uptime: 5h 23m 45s",
"ip_address": "10.0.0.3",
"gateway": "10.0.0.1",
"uptime_ms": 19425000
}
}
```
Subscribe to `vesper/+/status/heartbeat` to discover all online devices.
### Alert Payload (`vesper/{id}/status/alerts`)
Published only when a subsystem state changes. The server should store the active alert set per device and update the display in place rather than appending a log entry.
```json
{ "subsystem": "FileManager", "state": "WARNING", "msg": "ConfigManager health check failed" }
```
On recovery:
```json
{ "subsystem": "FileManager", "state": "CLEARED" }
```
`state` values: `WARNING` | `CRITICAL` | `FAILED` | `CLEARED`
### Info Payload (`vesper/{id}/status/info`)
Published on significant device state changes. `type` identifies the event; `payload` is event-specific.
```json
{ "type": "playback_started", "payload": { "melody_uid": "ABC123" } }
{ "type": "playback_stopped", "payload": {} }
```
---
## 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` |