feat(Player,MQTT): add pid/speed/duration/started_at/source/ts to status/playback (F-064)
The remote phone app treats status/playback as the source of truth for what the board is doing, but the payload couldn't say what was playing, and a client receiving a stale retained message couldn't work out real elapsed time. Adds (old fields kept): - pid, speed, duration (effective stop timer after mode/legacy resolution) - started_at / ts — Unix epoch s (UTC); system clock once NTP-synced, else new Timekeeper::getUtcEpoch() (RTC local time minus configured offsets), else 0 - source — app | rf | button | schedule | unknown. Carried, not guessed: new CommandEnvelope::origin set by each transport (MQTT/WS/HTTP → APP, UART slave board → BUTTON), mapped by PlaybackHandler; RFRemote passes RF New PlaybackState.hpp has one PlaybackSnapshot::writeTo() used for both the WebSocket INFO broadcast (under "payload") and MQTT status/playback (flat), so local and remote clients match. publishPlayback() now honours the hasHeapForPublish() guard before building the document. Bumps FW_VERSION to 2.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,19 +87,47 @@ to `status/heartbeat` (QoS 1, retained), overwriting the last "online" heartbeat
|
||||
|
||||
**QoS:** 1 — **Retained:** yes — **Switch:** `playback` — **Trigger:** playback state transition only
|
||||
|
||||
Published by `Player::setStatus()` on every transition (not polled).
|
||||
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.
|
||||
|
||||
```json
|
||||
{ "action": "playing", "time_elapsed": 12, "projected_run_time": 45000 }
|
||||
{
|
||||
"action": "playing",
|
||||
"time_elapsed": 12,
|
||||
"projected_run_time": 45000,
|
||||
"pid": "westminster",
|
||||
"speed": 400,
|
||||
"duration": 120000,
|
||||
"started_at": 1790000000,
|
||||
"source": "app",
|
||||
"ts": 1790000012
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{ "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` \| `idle` |
|
||||
| `time_elapsed` | integer | Seconds since playback started (0 for `idle`) |
|
||||
| `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... } }`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user