feat(Player): "loading" status while a melody downloads + playback_failed report (F-068)
A play that needed a download was ACKed SUCCESS and then nothing was
visible until playback started — and a failed download was only logged.
- New PlayerStatus::LOADING: status/playback publishes action "loading"
(pid/speed/duration/source set) before the ACK, then "playing" on success
or "idle" on failure.
- On failure after the ACK, control/reports gets
{ "type": "playback_failed", "payload": { "pid", "reason" } } (and a WS
INFO of the same). The download task re-checks bells-disabled/overload
before playing.
- playback.stop / forceStop during LOADING cancels the pending start
("Download cancelled — playback will not start"); the transfer finishes
and is discarded. New plays are refused until it does, since the task
still owns pid/_melodySteps. A mutex serialises the task's cancel-check +
play() against the cancel path.
- "loading" is MQTT-only: v1 tablets map unknown WS playback actions to
"unavailable" (F-061 symptom). system.status reports LOADING; the v1
adapter maps it to "idle".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ Vesper publishes on eight MQTT topics (a ninth, `system/ota`, is reserved but no
|
||||
|-------|-----------|-----|----------|--------|---------|
|
||||
| `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}/control/reports` | Outbound | 1 | no | `reports` | Critical, unsolicited, time-sensitive board-initiated events (`bell_overload`, `playback_failed`) |
|
||||
| `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 |
|
||||
@@ -23,7 +23,7 @@ Vesper publishes on eight MQTT topics (a ninth, `system/ota`, is reserved but no
|
||||
| `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`.
|
||||
Subscribe to `vesper/+/#` to receive everything from all devices (fleet webserver pattern). The phone app subscribes to `control/ack`, `status/heartbeat`, `status/playback`, and `control/reports` (for `playback_failed`).
|
||||
|
||||
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](vesper_mqtt_topic_spec_v2.md#per-topic-onoff-switches) for the full mechanism (`mqtt.get_topics`/`mqtt.set_topics`).
|
||||
|
||||
@@ -113,13 +113,13 @@ Flat — no envelope wrapper.
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `action` | string | `playing` \| `paused` \| `stopping` \| `idle` — see [States](#states) |
|
||||
| `action` | string | `loading` \| `playing` \| `paused` \| `stopping` \| `idle` — see [States](#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) |
|
||||
| `pid` | string | Melody being played or loaded (`""` 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. |
|
||||
| `started_at` | integer | Unix epoch seconds (UTC) when playback started. `0` when idle, while `loading` (not started yet), 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. |
|
||||
|
||||
@@ -127,18 +127,25 @@ Flat — no envelope wrapper.
|
||||
|
||||
**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... } }`.
|
||||
```json
|
||||
{ "action": "loading", "time_elapsed": 0, "projected_run_time": 0, "pid": "ABC123", "speed": 400, "duration": 120000, "started_at": 0, "source": "app", "ts": 1790000100 }
|
||||
```
|
||||
|
||||
The WebSocket transport receives the same fields on every transition, wrapped in the legacy broadcast envelope: `{ "status": "INFO", "type": "playback", "payload": { ...fields above... } }` — **except `loading`, which is MQTT-only**: v1 tablets (WebSocket) map any unknown playback action to "unavailable", so WebSocket clients keep seeing `idle` → `playing` for a download.
|
||||
|
||||
### States
|
||||
|
||||
| `action` | Meaning | Entered from | Leaves to |
|
||||
|---|---|---|---|
|
||||
| `playing` | Bells are ringing. | `idle` (play accepted), `paused` (segment pause over) | `paused`, `stopping`, `idle` |
|
||||
| `loading` | A `playback.play` was accepted (ACK: `Melody download started — …`) and the melody is downloading to SD first. No bells yet; `pid` identifies what is coming. | `idle` | `playing` (download OK), `idle` (download failed → also a [`playback_failed`](#playback-failed-event) report; or `playback.stop` → cancelled) |
|
||||
| `playing` | Bells are ringing. | `idle` (play accepted), `loading` (download done), `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`.
|
||||
`playback.stop` during `playing`/`paused`/`stopping` cuts the bells immediately and goes straight to `idle` — it never passes through `stopping`. During `loading` it cancels the pending start (ACK `Download cancelled — playback will not start`); the transfer itself finishes in the background and is discarded. A new `playback.play` is rejected in every state except `idle` (and briefly after a cancelled download, until that transfer ends).
|
||||
|
||||
On a SUCCESS play ACK the board publishes `status/playback` **before** the ACK: `playing` (melody was local) or `loading` (download needed). The heartbeat's independently-derived `state` reports `idle` during `stopping`.
|
||||
|
||||
---
|
||||
|
||||
@@ -175,6 +182,21 @@ Published by `CommunicationRouter::sendBellOverloadNotification()` → `publishR
|
||||
| `payload.loads` | array of int | Strike count load per bell channel |
|
||||
| `payload.severity` | string | `WARNING` (≥60% load) or `CRITICAL` (≥90% load) |
|
||||
|
||||
### Playback failed event
|
||||
|
||||
Published by `CommunicationRouter::sendPlaybackFailedNotification()` from the melody download task when a `playback.play` was already ACKed SUCCESS (`Melody download started — …`) but playback never began. `status/playback` goes `loading` → `idle` at the same moment. Not sent when the download was cancelled by `playback.stop`.
|
||||
|
||||
```json
|
||||
{ "type": "playback_failed", "payload": { "pid": "ABC123", "reason": "Melody download failed" } }
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `payload.pid` | string | The melody that failed to start |
|
||||
| `payload.reason` | string | One of: `Melody download failed` (HTTP/SD failure), `Melody failed to load: file is empty or corrupt` (downloaded file unusable), `Playback blocked: bell mechanism is disabled (bells.enable)` / `Playback blocked: bell overload protection active — wait for the bells to cool` (conditions changed during the download) |
|
||||
|
||||
Like every `control/reports` event it carries no `req_id` — correlate with the command by `pid` (only one download can be pending at a time). WebSocket clients get the same as `{ "status": "INFO", "type": "playback_failed", "payload": { "pid", "reason" } }`.
|
||||
|
||||
---
|
||||
|
||||
## `vesper/{id}/system/alerts`
|
||||
@@ -353,7 +375,7 @@ Invalid JSON or a missing `cmd` field gets an `ERROR` reply on `control/ack` (`t
|
||||
```
|
||||
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/+/control/reports → surface immediately — critical, time-sensitive (bell_overload, playback_failed)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user