LegacyAdapter already translates incoming v1 requests to v2 internal commands, but v2 handler replies used v2-only conventions (namespaced type strings, data nested under "data", UPPERCASE status enum, object-keyed strike_counters). A v1-only Flutter app polling system.status never recognised the reply, hit its own 5s request timeout, and its catch block explicitly set the UI to "unavailable" — even though the device was playing correctly and had already replied in time. Not a connectivity bug; a pure reply-schema mismatch. Adds LegacyResponseAdapter, the reply-side mirror of LegacyAdapter: a narrow, allowlisted translator that rewrites a CommandResult back into v1 shape, but only for replies to requests whose original envelope version was 1. Wired into WebSocket, MQTT, and HTTP's general command path by capturing envelope.version before CommandBus::dispatch() overwrites it to 2. v2 clients and all other reply types are untouched, byte-for-byte. This is deliberately temporary migration scaffolding for the v1→v2 tablet rollout window, not new permanent architecture — designed to be deleted alongside LegacyAdapter in one PR once fleet telemetry shows zero v1 requests. Full rationale and removal steps in docs/architecture/legacy-response-adapter.md. Verified: pio run across all four environments (vesper-std-v1, agnus-v1, agnus-mini-v1, bespoke-rs485-v1). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
114 lines
7.2 KiB
Markdown
114 lines
7.2 KiB
Markdown
# Project Vesper — Documentation
|
|
|
|
Bell automation firmware for ESP32 (Kincony KC868-A6).
|
|
|
|
---
|
|
|
|
## Reference
|
|
|
|
| File | Description |
|
|
|---|---|
|
|
| [reference/api-reference.md](reference/api-reference.md) | **Firmware API v2** — all commands, transports, envelope format |
|
|
| [reference/firmware-variants.md](reference/firmware-variants.md) | PlatformIO environments, partition tables, build flags, OTA URLs |
|
|
| [reference/api-reference-v1-legacy.md](reference/api-reference-v1-legacy.md) | Old v1 API (pre-refactor) — kept for historical reference |
|
|
|
|
## Architecture
|
|
|
|
| File | Description |
|
|
|---|---|
|
|
| [architecture/communication-refactor-plan.md](architecture/communication-refactor-plan.md) | Full design doc for the v2 Communication subsystem (CommandBus, Handlers, Transports) |
|
|
| [architecture/legacy-response-adapter.md](architecture/legacy-response-adapter.md) | `LegacyResponseAdapter` — v2→v1 reply translation for the v1→v2 migration window (temporary, with removal steps) |
|
|
|
|
## Features
|
|
|
|
| File | Description |
|
|
|---|---|
|
|
| [features/feature-catalog.md](features/feature-catalog.md) | **Feature catalog** — index + details for every feature on the device |
|
|
| [features/heartbeat.md](features/heartbeat.md) | MQTT heartbeat — retained 30s status publish (detail doc, also in catalog as F-008) |
|
|
|
|
## Development
|
|
|
|
| File | Description |
|
|
|---|---|
|
|
| [dev/platformio-commands.md](dev/platformio-commands.md) | PlatformIO CLI reference |
|
|
| [dev/common-commands.md](dev/common-commands.md) | Common v1 command snippets (scratch/lab use) |
|
|
| [dev/features-scratch.md](dev/features-scratch.md) | Feature notes and todo scratch pad |
|
|
|
|
## Other
|
|
|
|
| File | Description |
|
|
|---|---|
|
|
| [roadmap.md](roadmap.md) | Product roadmap |
|
|
| [SentDevices/](SentDevices/) | Records of deployed devices |
|
|
|
|
|
|
## Working Rules (enforced in every session)
|
|
|
|
### Context
|
|
This is ESP32 firmware (C++/Arduino/PlatformIO) for a bell automation controller.
|
|
It is maintained by a **single developer over a long time**, with AI assistance.
|
|
That means both of us can forget what was built weeks ago — so we need hard process rules to compensate.
|
|
|
|
### Rules — non-negotiable
|
|
|
|
**1. Feature catalog is mandatory.**
|
|
Every feature added or changed must be logged in `docs/features/feature-catalog.md`.
|
|
Format: a short one-line entry in the index at the top, plus a detailed section below.
|
|
This is the single source of truth for "what does this device actually do?"
|
|
|
|
**2. Commit every meaningful step.**
|
|
Nothing stays uncommitted for long. Each logical unit of work (a fix, a feature, a refactor) gets its own commit with a clear message. Stacked uncommitted changes are a liability — they blur what changed and why.
|
|
|
|
**3. Commit messages are descriptive.**
|
|
`fix(InputManager): add medium-press tier at 5s for WiFi-only reset`
|
|
is better than `fix button`. The message must make sense to a reader in 6 months who has never seen this codebase.
|
|
|
|
**4. Feature catalog entry before (or with) the commit.**
|
|
When committing a feature or significant fix, the catalog entry is part of the same commit or committed immediately after. Never leave a feature undocumented.
|
|
|
|
**5. At the start of every session, check what is uncommitted.**
|
|
Before writing any new code, surface any dirty working tree and deal with it first — commit, discard, or document why it stays pending.
|
|
|
|
### Feature catalog location
|
|
`docs/features/feature-catalog.md`
|
|
|
|
### What counts as a "feature" for the catalog
|
|
- Any new user-facing behaviour (commands, button gestures, network modes, playback options)
|
|
- Any significant internal mechanism a future developer would need to know (e.g. two-tier factory reset, NTP UTC correction, builtin melody aliases)
|
|
- Bug fixes that change observable behaviour (e.g. default version fallback changed from 2→1)
|
|
|
|
### What does NOT need a catalog entry
|
|
- Pure refactors with no behaviour change
|
|
- Log message tweaks
|
|
- Doc-only commits
|
|
|
|
**6. Console API Reference is mandatory.**
|
|
Any new command/API endpoint, or a change to an existing one's contents/response/errors, must be reflected in the console's live API Reference page — not just in `docs/reference/api-reference.md`. The two are separate files in separate repos and neither auto-syncs from the other; both must be updated by hand in the same change.
|
|
|
|
### Console API Reference location
|
|
`C:\development\bellsystems-cp\frontend\src\pages\engineering\developer\ApiReferencePage.jsx`
|
|
|
|
This is a different repo (`bellsystems-cp`, the backend/console repo) from this firmware repo (`project-vesper`) — open it directly by path, it will not show up in a search scoped to this repo.
|
|
|
|
### How to update it
|
|
Commands are grouped into a `NAMESPACES` array. Each entry is `{ id, label, description, commands: [...] }` — one entry per namespace (e.g. `system`, `clock`, `relay`, `ota`, `firmware`, `network`, or `root` for commands with no prefix). Find the matching namespace (or add a new one) and add/edit a command object in its `commands` array with these fields:
|
|
|
|
| Field | Required | Meaning |
|
|
|---|---|---|
|
|
| `cmd` | yes | Full command name, e.g. `"clock.set_time"` |
|
|
| `handler` | yes | The C++ handler class that services it, e.g. `"ClockHandler"` |
|
|
| `transports` | yes | Array/label of which transports accept it — usually `['All']`; narrow it if the command is transport-restricted (e.g. `identify` is WebSocket-only, `ping` is unavailable on RTC-less variants) |
|
|
| `description` | yes | What the command does, plus any caveats (rejection conditions, variant restrictions, blocking behaviour) |
|
|
| `contents` | yes (`null` if none) | Array of request fields, or `null` if the command takes no `contents` body |
|
|
| `contents[].field` | yes | Field name as it appears in the JSON `contents` object |
|
|
| `contents[].type` | yes | Wire type: `string`, `int`, `bool`, `int[]`, `object`, etc. |
|
|
| `contents[].required` | yes | `true`/`false` — whether the field is mandatory. If a command requires "at least one of" a set of optional fields, say so in `notes` on each and add an error entry for the all-missing case |
|
|
| `contents[].notes` | yes | What the field means, valid ranges/values, 0-based vs 1-based indexing (call this out explicitly — this API mixes both), defaults, and interactions with other fields |
|
|
| `response` | yes | Exact success wire-format JSON as a string, matching the real `{ "status": "SUCCESS", "type": "<cmd>", "message"/"data": ... }` envelope the firmware actually sends |
|
|
| `errors` | yes (`[]` if none) | Array of `{ message, condition }` — `message` is the exact error string the firmware emits, `condition` is when it fires. Should cover every `CommandResult::err()` path in the handler |
|
|
| `example` | yes | One or more realistic full request JSON payloads (`{ "v": 2, "cmd": "...", "contents": {...} }`), as a string |
|
|
| `warning` | yes (`null` if none) | Set for anything destructive or irreversible (reboot, factory reset, rollback) — short caller-facing warning string |
|
|
|
|
When adding a **new namespace**, also check `UART_WHITELIST` near the top of the file — if the command should be reachable over UART, add its name there too (UART only accepts whitelisted commands).
|
|
|
|
Keep `docs/reference/api-reference.md` (this repo) and the console page in sync — update both in the same change whenever a command is added or changed. |