feat: multi-board HAL guards, RFRemote subsystem, Player/OTA improvements
Multi-board variant support: - variants/vesper.hpp: enable HAS_RF=1, define RF_RX_PIN=22 - variants/agnus.hpp: enable HAS_RF=1, RF_RX_PIN=22, correct HAS_RTC=0 - main.cpp, Player, HealthMonitor, OTAManager, ConfigManager: wrap all RTC/SD/RF-dependent code in #if HAS_RTC / HAS_SD_CARD / HAS_RF guards so Agnus builds cleanly without those peripherals RFRemote subsystem (new): - src/RFRemote/: RF receiver driver (GPIO RF_RX_PIN) + command handler - Registered with HealthMonitor and CommunicationRouter when HAS_RF=1 Player improvements: - uid -> pid rename throughout (Player, BuiltInMelodies, api-reference) - loadMelodyInRAM() now returns bool - playerControlTaskFn task added — defers stop/pause/resume out of timer callback (Tmr Svc) to avoid stack overflows - setDependencies() accepts nullptr FileManager for SD-less boards OTAManager: - Consume download_url from server metadata response instead of constructing firmware path locally - HTTP redirect following enabled (setFollowRedirects) - HAS_RTC guards on TimeKeeper references platformio.ini: - Add rc-switch library for RF remote support - Remove BOARD_TYPE/BOARD_NAME/BOARD_VERSION flags (moved to variant headers) - MQTT_SECRET placeholders only — no secrets in source Docs: - docs/architecture/codebase-refactor-plan.md: new migration strategy doc - docs/reference/api-reference.md: updated for pid, note_assignments, download_url - Remove stale docs: ota-telemetry-api.md, platformio-commands.md, firmware-variants.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
# OTA Telemetry API — Backend Endpoints Required
|
||||
|
||||
The firmware POSTs two events during an OTA update. Both are **best-effort** — a failure does not abort the update. The device does not retry on failure.
|
||||
|
||||
---
|
||||
|
||||
## 1. Download Event
|
||||
|
||||
**Trigger:** Firmware binary fully written to the staged flash partition, before `Update.end()` is called. The new firmware is not yet active.
|
||||
|
||||
**Method:** `POST`
|
||||
**Path:** `/api/ota/events/download`
|
||||
|
||||
### Request Body (JSON)
|
||||
|
||||
```json
|
||||
{
|
||||
"device_uid": "PV000000000000",
|
||||
"hw_type": "vesper",
|
||||
"hw_version": "1.0",
|
||||
"from_version": "1.2.3",
|
||||
"to_version": "1.3.0",
|
||||
"channel": "stable"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|----------------|--------|-----------------------------------------------------------------------|
|
||||
| `device_uid` | string | Unique device identifier from NVS |
|
||||
| `hw_type` | string | Hardware type code (e.g. `vesper`, `vesper-plus`, `vesper-pro`) |
|
||||
| `hw_version` | string | Hardware revision from NVS (e.g. `1.0`) |
|
||||
| `from_version` | string | Semver of the firmware currently running |
|
||||
| `to_version` | string | Semver of the firmware that was just downloaded |
|
||||
| `channel` | string | Update channel (`stable`, `beta`, etc.) |
|
||||
|
||||
### Expected Response
|
||||
|
||||
Any `2xx` status is accepted. Recommended: `204 No Content`.
|
||||
|
||||
---
|
||||
|
||||
## 2. Flash Event
|
||||
|
||||
**Trigger:** `Update.end()` succeeded — the new partition is committed and the device is about to restart. This is the most reliable signal that the update actually landed.
|
||||
|
||||
**Method:** `POST`
|
||||
**Path:** `/api/ota/events/flash`
|
||||
|
||||
### Request Body (JSON)
|
||||
|
||||
```json
|
||||
{
|
||||
"device_uid": "PV000000000000",
|
||||
"hw_type": "vesper",
|
||||
"hw_version": "1.0",
|
||||
"from_version": "1.2.3",
|
||||
"to_version": "1.3.0",
|
||||
"channel": "stable",
|
||||
"sha256": "a3f1...64hexchars...b9e2"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|----------------|--------|-------------------------------------------------------|
|
||||
| `device_uid` | string | Unique device identifier from NVS |
|
||||
| `hw_type` | string | Hardware type code |
|
||||
| `hw_version` | string | Hardware revision from NVS |
|
||||
| `from_version` | string | Semver of the firmware that was running |
|
||||
| `to_version` | string | Semver of the firmware now committed to flash |
|
||||
| `channel` | string | Update channel |
|
||||
| `sha256` | string | SHA256 of the downloaded binary (from `/latest` metadata) |
|
||||
|
||||
### Expected Response
|
||||
|
||||
Any `2xx` status is accepted. Recommended: `204 No Content`.
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- Both requests use the **primary server only** (`servers[0]` from the configured list). No retry, no fallback server attempt.
|
||||
- Timeout is hardcoded to **5 seconds** to avoid blocking the reboot.
|
||||
- If WiFi is not connected at the time of the POST, the call is silently skipped.
|
||||
- The difference between the two events: `download` tells you the device received the binary; `flash` tells you the partition was committed. A device that posts `download` but never posts `flash` may have had a verification failure — worth flagging in the backend.
|
||||
|
||||
---
|
||||
|
||||
## Suggested Backend Behaviour
|
||||
|
||||
- Store both events in a `firmware_events` table with a `type` column (`download` / `flash`).
|
||||
- Index by `device_uid` + `to_version` to detect partial failures (download without flash).
|
||||
- Use the `flash` event to drive the "current fleet version" dashboard — it is the ground truth.
|
||||
|
||||
---
|
||||
|
||||
## Backend Changes Required — Upgrade Chain Resolution
|
||||
|
||||
### Background
|
||||
|
||||
The firmware sends its current version and hardware revision as query parameters on every version check:
|
||||
|
||||
```
|
||||
GET /api/firmware/{hw_type}/{channel}/latest?hw_version=1.0¤t_version=5.7.1
|
||||
```
|
||||
|
||||
Both parameters are optional. The server must use `current_version` to resolve upgrade chains and return the **correct next hop** rather than blindly returning the absolute latest. The device trusts whatever version the server returns and installs it.
|
||||
|
||||
`hw_version` allows the server to filter firmware releases to those compatible with the device's specific hardware revision — useful when a hardware change between revisions requires a different binary.
|
||||
|
||||
**Example:** Device is on `5.7.1`. Latest is `7.2.2` but has `min_fw_version = 6.0.0`.
|
||||
- Without chain resolution → server returns `7.2.2` → device cannot install → update silently fails.
|
||||
- With chain resolution → server returns `6.0.0` → device installs it → on next boot, server returns `7.2.2` → device installs it.
|
||||
|
||||
---
|
||||
|
||||
### Changes needed in `/api/firmware/{hw_type}/{channel}/latest`
|
||||
|
||||
1. **Accept `hw_version` and `current_version` as optional query parameters** (both strings). If absent or unparseable, fall back to current behaviour (return absolute latest, no hw revision filtering).
|
||||
|
||||
2. **Resolve the next hop:**
|
||||
```
|
||||
query all published versions for (hw_type, channel), ordered ascending
|
||||
find the lowest version V where:
|
||||
V > current_version
|
||||
AND (V.min_fw_version is null OR current_version >= V.min_fw_version)
|
||||
return V
|
||||
```
|
||||
If no such version exists (current is already at latest, or all higher versions have unsatisfied min_fw_version), return `404` or the current version with no update flag.
|
||||
|
||||
3. **The response shape does not change** — same fields as today. The device doesn't need to know it received an intermediate version rather than the latest.
|
||||
|
||||
### Example query logic (pseudo-SQL)
|
||||
|
||||
```sql
|
||||
SELECT * FROM firmware_releases
|
||||
WHERE hw_type = :hw_type
|
||||
AND channel = :channel
|
||||
AND version > :current_version
|
||||
AND (min_fw_version IS NULL OR :current_version >= min_fw_version)
|
||||
AND (min_hw_version IS NULL OR :hw_version >= min_hw_version) -- optional hw revision gate
|
||||
ORDER BY version ASC -- semver-aware sort
|
||||
LIMIT 1;
|
||||
```
|
||||
|
||||
> Note: semver ordering must be numeric (`1.10.0 > 1.9.0`), not lexicographic. Use a semver-aware sort or store major/minor/patch as separate integer columns.
|
||||
|
||||
### Edge cases to handle
|
||||
|
||||
| Scenario | Expected behaviour |
|
||||
|---|---|
|
||||
| `hw_version` absent / malformed | Ignore param, skip hw revision filtering |
|
||||
| `current_version` absent / malformed | Ignore param, return absolute latest (existing behaviour) |
|
||||
| Device already at latest | Return `404` or `200` with a "no update" indicator — firmware handles both |
|
||||
| No version satisfies the chain constraint | Return `404` — firmware logs and skips |
|
||||
| Multiple intermediate hops needed | Server returns only the immediate next hop; device re-checks after each reboot and walks the chain naturally |
|
||||
Reference in New Issue
Block a user