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:
@@ -78,7 +78,7 @@ MQTT uses the v2 topic set — see [vesper_mqtt_topic_spec_v2.md](vesper_mqtt_to
|
||||
|---|---|---|---|
|
||||
| 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}/control/reports` | Outbound, critical unsolicited events | `bell_overload`, `playback_failed` — not retained |
|
||||
| MQTT | `vesper/{device_id}/status/heartbeat` | Outbound, retained, QoS 1 | Heartbeat every 30s + LWT |
|
||||
| MQTT | `vesper/{device_id}/status/playback` | Outbound, retained, QoS 1 | Playback transitions |
|
||||
| MQTT | `vesper/{device_id}/system/alerts` | Outbound, retained until cleared, QoS 1 | Subsystem state-change events |
|
||||
@@ -167,7 +167,7 @@ Both commands reply with **`type: "playback"`** (not the command name).
|
||||
| Transports | MQTT, WebSocket, HTTP (UART: v1 form only) |
|
||||
| Returns | `{ "status": "SUCCESS", "type": "playback", "message": "Playback started" }` — or `"message": "Melody download started — playback begins when it completes"` when the melody must be downloaded first |
|
||||
|
||||
The SUCCESS reply means the board **accepted** the command, not that bells are ringing. `status/playback` (MQTT) is the source of truth for what the board is actually doing — `playing` / `paused` / `stopping` / `idle`; see [mqtt-events.md → States](mqtt-events.md#states).
|
||||
The SUCCESS reply means the board **accepted** the command, not that bells are ringing. `status/playback` (MQTT) is the source of truth for what the board is actually doing — `loading` / `playing` / `paused` / `stopping` / `idle`; see [mqtt-events.md → States](mqtt-events.md#states).
|
||||
|
||||
**Fields are sticky.** Every field except `url`, `mode` and `continuous_loop` keeps the value from the *previous* `playback.play` (or its boot default) when omitted — including `pid`, `speed` and the tail of `note_assignments`. Send every field you care about on every play. A rejected play never changes the stored values (all checks run first).
|
||||
|
||||
@@ -206,7 +206,8 @@ Errors are checked in this order; the first that applies is returned. Every one
|
||||
|
||||
| Error `message` | Condition |
|
||||
|---|---|
|
||||
| `Playback already active — send playback.stop first` | Player is not idle (`playing` / `paused` / `stopping`) |
|
||||
| `Playback already active — send playback.stop first` | Player is not idle (`loading` / `playing` / `paused` / `stopping`) |
|
||||
| `Playback blocked: a cancelled melody download is still finishing — try again shortly` | A download was cancelled by `playback.stop` and its transfer hasn't ended yet |
|
||||
| `Missing required field: pid` | No `pid`/`uid` in this command and none stored from a previous play; or it is empty, `"-"`, or not a string |
|
||||
| `Invalid speed: must be an integer from 0 to 65535 (ms per beat)` | `speed` present but not an integer in range |
|
||||
| `Invalid note_assignments: must be an array of up to 16 integers, each 0-16` | Not an array, more than 16 entries, or an entry outside 0–16 |
|
||||
@@ -222,7 +223,13 @@ Errors are checked in this order; the first that applies is returned. Every one
|
||||
| `Melody not found: not built-in, not on SD card, and no url given` | Needs a download but no `url` was sent |
|
||||
| `Melody not found locally and this device has no SD card to download it to` | Needs a download but the build has no SD card / FileManager (agnus) |
|
||||
|
||||
A download itself happens **after** the SUCCESS reply (it would otherwise block the network task for seconds), so a failed download can't be an ACK error — the board logs `Melody download failed` (or `Melody failed to load: …` for a bad downloaded file) and playback simply doesn't start.
|
||||
**Download path.** When the melody must be downloaded, the ACK is SUCCESS `Melody download started — playback begins when it completes`, and `status/playback` shows **`loading`** (with `pid` set) — published just before the ACK. The download runs after the reply (it would otherwise block the network task for seconds), so its failure can't be an ACK error. Instead:
|
||||
|
||||
- success → `status/playback` goes `loading` → `playing`;
|
||||
- failure → `status/playback` goes `loading` → `idle` **and** a [`playback_failed`](mqtt-events.md#playback-failed-event) event `{ "pid", "reason" }` is published on `control/reports` (reason: `Melody download failed`, `Melody failed to load: file is empty or corrupt`, or one of the two `Playback blocked: …` messages if conditions changed during the download);
|
||||
- `playback.stop` while `loading` → cancelled, `idle`, no `playback_failed`.
|
||||
|
||||
The ACK itself is always sent synchronously from the command's own dispatch, so `req_id` is echoed on it in both the local and the download case. `playback_failed` (like every `control/reports` event) carries no `req_id` — match it by `pid`.
|
||||
|
||||
```json
|
||||
{ "v": 2, "req_id": "a1", "cmd": "playback.play", "contents": { "pid": "westminster", "speed": 400, "mode": "single" } }
|
||||
@@ -241,6 +248,8 @@ A download itself happens **after** the SUCCESS reply (it would otherwise block
|
||||
|
||||
Stops immediately (bells are cut mid-loop, status goes straight to `idle`).
|
||||
|
||||
**While `loading` → SUCCESS**, `"message": "Download cancelled — playback will not start"` (status goes `loading` → `idle`; the transfer finishes in the background and is discarded).
|
||||
|
||||
**Already idle → SUCCESS**, `"message": "Already stopped"` (no status/playback publish, since nothing changed). Stop is idempotent: the caller's goal state is reached, so it is not an error — the distinct message lets a client tell the two cases apart if it cares. `playback.stop` has no error replies.
|
||||
|
||||
```json
|
||||
@@ -503,9 +512,9 @@ Fire C1/C2 for the configured pulse. Returns `data: { "output": "C1", "duration_
|
||||
|
||||
### `system.status`
|
||||
|
||||
Returns `data: { "player_status": "PLAYING"|"PAUSED"|"STOPPING"|"STOPPED", "time_elapsed_ms", "projected_run_time", "strike_counters": { "0": 1234, ... } }`.
|
||||
Returns `data: { "player_status": "PLAYING"|"PAUSED"|"STOPPING"|"LOADING"|"STOPPED", "time_elapsed_ms", "projected_run_time", "strike_counters": { "0": 1234, ... } }`.
|
||||
|
||||
A **v1** request (no `v`, or `v:1`) gets the reply translated by `LegacyResponseAdapter`: `type: "current_status"`, fields under `payload` (not `data`), lowercase `player_status` (`playing`/`paused`/`stopping`/`idle`), `time_elapsed` (ms), `strike_counters` as an array.
|
||||
A **v1** request (no `v`, or `v:1`) gets the reply translated by `LegacyResponseAdapter`: `type: "current_status"`, fields under `payload` (not `data`), lowercase `player_status` (`playing`/`paused`/`stopping`/`idle` — `LOADING` is reported as `idle`), `time_elapsed` (ms), `strike_counters` as an array.
|
||||
|
||||
### `system.get_time`
|
||||
|
||||
@@ -517,7 +526,7 @@ Full ConfigManager dump plus `general: { bells_enabled, mqtt_enabled, ota_channe
|
||||
|
||||
### `system.get_all`
|
||||
|
||||
Returns `data: { "device": { serial, hw_family, hw_revision, fw_version, uptime_ms, free_heap }, "config": {...}, "telemetry": {...}, "player": { "status": "PLAYING"|"PAUSED"|"STOPPING"|"STOPPED" } }`.
|
||||
Returns `data: { "device": { serial, hw_family, hw_revision, fw_version, uptime_ms, free_heap }, "config": {...}, "telemetry": {...}, "player": { "status": "PLAYING"|"PAUSED"|"STOPPING"|"LOADING"|"STOPPED" } }`.
|
||||
|
||||
### `system.get_telemetry`
|
||||
|
||||
@@ -865,7 +874,7 @@ Published without a request, on the v2 topic set. Full field-level reference: [m
|
||||
|---|---|---|---|---|
|
||||
| `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}/control/reports` | Critical unsolicited events (`bell_overload`, `playback_failed`) | 1 | no | `reports` |
|
||||
| `vesper/{id}/system/alerts` | On subsystem state change only | 1 | yes, until cleared | `alerts` |
|
||||
| `vesper/{id}/system/info` | Discrete device events (e.g. boot report) | 1 | yes | `info` |
|
||||
| `vesper/{id}/system/logs` | Mirrors serial log stream | 0 | no | `logs` |
|
||||
|
||||
Reference in New Issue
Block a user