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:
2026-03-17 17:02:01 +02:00
co-authored by Claude Sonnet 4.6
parent 37b65cc15a
commit a4d071d5d5
31 changed files with 2431 additions and 891 deletions
+167 -7
View File
@@ -2,7 +2,7 @@
> Command reference for the Vesper Bell Automation System.
> Firmware v2 command bus architecture — all transports, all handlers.
> Last updated: 2026-03-01
> Last updated: 2026-03-16
---
@@ -122,10 +122,22 @@ WebSocket clients must send `identify` immediately after connecting, or they wil
`action` values: `"play"`, `"stop"`, `"pause"`, `"unpause"`
```json
{ "v": 2, "cmd": "playback", "contents": { "action": "play", "melody_uid": "ABC123" } }
{ "v": 2, "cmd": "playback", "contents": { "action": "play", "pid": "ormilia_1_8", "speed": 200, "total_duration": 60000, "note_assignments": [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0] } }
{ "v": 2, "cmd": "playback", "contents": { "action": "stop" } }
```
| Field | Type | Required | Notes |
|---|---|---|---|
| `action` | string | yes | `"play"` or `"stop"` |
| `pid` | string | yes (play) | Playback ID. Checked against built-in library first, then SD card, then downloaded via `download_url`. |
| `download_url` | string | no | URL to download the melody binary if not found locally. |
| `speed` | int | no | ms per beat. Default 500. |
| `total_duration` | int | no | Total playback ms. `0` = play to natural end. |
| `segment_duration` | int | no | Duration per loop segment (ms). Used with `continuous_loop`. |
| `pause_duration` | int | no | Pause between segments (ms). |
| `continuous_loop` | bool | no | Loop with pause/resume segments. |
| `note_assignments` | int[16] | no | Bell mapping (0-indexed note → 1-indexed output, 0 = unused). |
---
## Relay Namespace — `RelayHandler`
@@ -620,7 +632,7 @@ List all built-in melodies compiled into the firmware.
| | |
|---|---|
| Returns | `[{ "name": "...", "uid": "..." }, ...]` |
| Returns | `[{ "name": "...", "pid": "..." }, ...]` |
```json
{ "v": 2, "cmd": "files.list_builtin" }
@@ -672,19 +684,166 @@ Set log verbosity per output channel. Level 0 = off, 5 = verbose.
### `log.set_serial`
```json
{ "v": 2, "cmd": "log.set_serial", "contents": { "level": 3 } }
{ "v": 2, "cmd": "log.set_serial", "contents": { "level": 0 } }
```
### `log.set_sd`
```json
{ "v": 2, "cmd": "log.set_sd", "contents": { "level": 2 } }
{ "v": 2, "cmd": "log.set_sd", "contents": { "level": 0 } }
```
### `log.set_mqtt`
```json
{ "v": 2, "cmd": "log.set_mqtt", "contents": { "level": 1 } }
{ "v": 2, "cmd": "log.set_mqtt", "contents": { "level": 0 } }
```
---
## RF Remote Namespace — `RFRemoteHandler`
> Available on hardware variants with `HAS_RF=1` (e.g. Vesper, Vesper+).
> All commands are silently rejected on variants without RF hardware.
The RF subsystem uses a **slot model**: up to 16 independent slots, each binding one RF trigger code to a complete playback action. Slots are blank by default — nothing is pre-seeded. Program them over MQTT after flashing.
### Slot object
| Field | Type | Required | Notes |
|---|---|---|---|
| `slot` | int | yes | Slot index, 0–15 |
| `rf_code` | uint32 | yes | Raw 433 MHz code that triggers this slot. Must be non-zero. |
| `pid` | string | yes (play) | Playback ID. Checked against built-in library first, then SD card. Use `files.list_builtin` or `files.list` for valid PIDs. |
| `speed` | int | no | ms per beat. Default 500. |
| `duration` | int | no | Total playback ms. Default 30000. `0` = play to natural end. |
| `note_assignments` | int[16] | no | Bell mapping array (0-indexed note → 1-indexed bell output, 0 = unused). Default all zeros. |
| `is_stop` | bool | no | If `true`, receiving this code calls force-stop (single press, no long-press required). `pid`/`speed`/`duration` ignored. Default `false`. |
**`note_assignments` example:** A melody written for 6 bells played on 3 physical bells, doubled:
```json
"note_assignments": [1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
```
---
### `rf.set_slot`
Program one slot, or multiple slots in a single command.
| | |
|---|---|
| Handler | RFRemoteHandler |
| Transports | All |
| Persists | NVS namespace `rf` (survives reboot) |
**Single slot:**
```json
{
"v": 2,
"cmd": "rf.set_slot",
"contents": {
"slot": 0,
"rf_code": 9274392,
"pid": "vesper_fst_1_4",
"speed": 500,
"duration": 60000,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"is_stop": false
}
}
```
**Multiple slots (batch):**
```json
{
"v": 2,
"cmd": "rf.set_slot",
"contents": {
"slots": [
{ "slot": 0, "rf_code": 9274392, "pid": "vesper_fst_1_4", "speed": 500, "duration": 60000, "note_assignments": [1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0] },
{ "slot": 1, "rf_code": 9274388, "pid": "doxology_1_4", "speed": 500, "duration": 60000 },
{ "slot": 7, "rf_code": 9274385, "is_stop": true }
]
}
}
```
Returns:
```json
{ "status": "SUCCESS", "type": "rf.set_slot", "payload": "3 slot(s) programmed" }
```
---
### `rf.clear_slot`
Clear a single slot, or all slots.
| | |
|---|---|
| Required | `slot` — int (0–15) or string `"all"` |
```json
{ "v": 2, "cmd": "rf.clear_slot", "contents": { "slot": 3 } }
{ "v": 2, "cmd": "rf.clear_slot", "contents": { "slot": "all" } }
```
---
### `rf.get_slots`
Return the full slot table (all 16 slots).
| | |
|---|---|
| Contents | *(none)* |
| Returns | `{ "enabled": bool, "slots": [ { slot object } × 16 ] }` |
Each entry includes an `"empty": true/false` field. Empty slots have `rf_code: 0` and all other fields at their defaults.
```json
{ "v": 2, "cmd": "rf.get_slots" }
```
Example response excerpt:
```json
{
"status": "SUCCESS",
"type": "rf.get_slots",
"data": {
"enabled": true,
"slots": [
{
"slot": 0,
"empty": false,
"rf_code": 9274392,
"pid": "vesper_fst_1_4",
"speed": 500,
"duration": 60000,
"is_stop": false,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
{ "slot": 1, "empty": true, "rf_code": 0, ... },
...
]
}
}
```
---
### `rf.enable`
Enable or disable RF reception at runtime.
| | |
|---|---|
| Required | `enabled` (bool) |
```json
{ "v": 2, "cmd": "rf.enable", "contents": { "enabled": true } }
{ "v": 2, "cmd": "rf.enable", "contents": { "enabled": false } }
```
---
@@ -799,7 +958,7 @@ On recovery:
Published on significant device state changes. `type` identifies the event; `payload` is event-specific.
```json
{ "type": "playback_started", "payload": { "melody_uid": "ABC123" } }
{ "type": "playback_started", "payload": { "pid": "ormilia_1_8" } }
{ "type": "playback_stopped", "payload": {} }
```
@@ -870,3 +1029,4 @@ If a client sends `"v": 1` (or omits `v`), the `LegacyAdapter` translates the ol
| `log` | `set_serial`, `set_sd`, `set_mqtt` |
| `mqtt` | `enable`, `disable` |
| `telemetry` | `get_strikes`, `reset_strikes`, `get_loads` |
| `rf` | `set_slot`, `clear_slot`, `get_slots`, `enable` *(HAS_RF variants only)* |
-178
View File
@@ -1,178 +0,0 @@
# Firmware Variants — Project Vesper
> Reference for all PlatformIO build environments defined in `vesper/platformio.ini`.
---
## Active Environments
### `vesper-v1` — Vesper (VS)
| Property | Value |
|---|---|
| Board | Kincony KC868-A6 |
| MCU | ESP32-D0WD-V3 (rev 3.1) |
| PlatformIO board target | `esp32dev` |
| Flash size | 4 MB |
| Partition table | `min_spiffs.csv` |
| Board type code | `VS` |
| Board version | `01` |
| PSRAM | No |
| RF remote | No |
| Onboard LCD | No |
**Partition layout (`min_spiffs.csv`):**
| Partition | Address | Size |
|---|---|---|
| nvs | `0x9000` | 20 KB (0x5000) |
| app0 (active) | `0x10000` | ~1.8 MB |
| app1 (OTA) | `0x1F0000` | ~1.8 MB |
| spiffs | `0x3D0000` | 128 KB |
**Build:**
```bash
# From repo root
pio run -e vesper-v1
# Output: vesper/.pio/build/vesper-v1/firmware.bin
```
**Full erase + upload:**
```bash
pio run -e vesper-v1 --target upload --upload-port COM8
```
**Flash NVS after full upload** (NVS is wiped by full erase — must reflash separately):
```bash
C:/Users/espi_/.espressif/python_env/idf5.4_py3.11_env/Scripts/python.exe \
-m esptool --chip esp32 --port COM8 --baud 921600 \
write_flash 0x9000 vesper/provisioning/nvs_lab_device.bin
```
**Serial monitor:**
```bash
pio device monitor # 115200 baud
```
**OTA URL pattern (VPS NGINX):**
```
http://72.61.191.197/ota/vs/stable/firmware.bin
http://72.61.191.197/ota/vs/{channel}/firmware.bin
```
Channels: `stable`, `beta`
**Key build flags:**
```ini
-DBOARD_TYPE="VS"
-DBOARD_VERSION="01"
-DBOARD_NAME="Vesper"
-DPSRAM_ENABLED=0
-DHAS_RF=0
-DHAS_LCD=0
-DMQTT_SECRET="<set-locally-not-committed>"
```
> **Important:** `MQTT_SECRET` must match the `MQTT_SECRET` in the backend `.env` on the VPS.
> Never commit the real secret. Override locally via a `platformio.ini.local` file (gitignored):
> ```ini
> [env:vesper-v1]
> build_flags =
> ... (copy existing flags) ...
> -DMQTT_SECRET=\"your_actual_secret\"
> ```
---
## Planned Environments (Not Yet Active)
### `vesper-plus-v1` — Vesper+ (VP)
| Property | Value |
|---|---|
| Board target | `esp32dev` |
| Board type code | `VP` |
| RF remote | **Yes** (`HAS_RF=1`) |
| Onboard LCD | No |
| Status | Commented out in `platformio.ini` |
**When activated, upload command:**
```bash
pio run -e vesper-plus-v1 --target upload --upload-port <PORT>
```
**OTA URL pattern:**
```
http://72.61.191.197/ota/vp/stable/firmware.bin
```
---
### `vesper-pro-v1` — Vesper Pro (VX)
| Property | Value |
|---|---|
| Board target | `esp32dev` |
| Board type code | `VX` |
| RF remote | No |
| Onboard LCD | **Yes** (`HAS_LCD=1`) |
| Status | Commented out in `platformio.ini` |
**When activated, upload command:**
```bash
pio run -e vesper-pro-v1 --target upload --upload-port <PORT>
```
**OTA URL pattern:**
```
http://72.61.191.197/ota/vx/stable/firmware.bin
```
---
## NVS Identity (All Variants)
Each device has a pre-flashed NVS partition at `0x9000` containing:
| NVS namespace | Key | Example |
|---|---|---|
| `device_id` | `device_uid` | `PV-26B18-VS01R-X7KQA` |
| `device_id` | `hw_type` | `VS` |
| `device_id` | `hw_version` | `01` |
NVS binaries are generated by the admin console at:
```
GET /api/manufacturing/devices/{sn}/nvs.bin
```
The lab device NVS CSV and binary live at:
```
vesper/provisioning/nvs_lab_device.csv
vesper/provisioning/nvs_lab_device.bin
```
---
## Shared Library Dependencies
All variants share the same `lib_deps` (defined in `[common]`):
| Library | Purpose |
|---|---|
| `tzapu/WiFiManager` | WiFi provisioning captive portal |
| `me-no-dev/ESPAsyncWebServer` | Async HTTP server + WebSocket |
| `me-no-dev/AsyncTCP` | Async TCP (required by above) |
| `bblanchon/ArduinoJson` | JSON parsing (v7) |
| `adafruit/Adafruit PCF8574` | I2C GPIO expander (relay control) |
| `adafruit/RTClib` | Real-time clock |
| `marvinroger/async-mqtt-client` | Async MQTT client |
---
## Adding a New Variant
1. Copy a `[env:vesper-*]` block in `vesper/platformio.ini` and uncomment it.
2. Set the correct `BOARD_TYPE`, `BOARD_VERSION`, `HAS_RF`, `HAS_LCD` flags.
3. Add the new `BoardType` value to `backend/manufacturing/models.py` (`BoardType` enum and `BOARD_TYPE_LABELS`).
4. Add the NVS gen path for the new `hw_type` in `backend/utils/nvs_generator.py` if needed.
5. Create the NGINX OTA directory on the VPS: `/srv/ota/{new_type}/stable/`.
6. Upload a firmware binary and update the firmware manager entry.