Controller B updates from A: link_peer (pairing over the wire, encrypted credential handoff, B status + commands), ESP-NOW receive/unicast, Updates page with two cards; shared header maintenance frames; docs + wiki
Firmware / build (push) Successful in 7m1s

This commit is contained in:
2026-09-27 20:26:44 +02:00
parent 8338e4e300
commit 3e86ca3733
20 changed files with 884 additions and 50 deletions
+19 -7
View File
@@ -1,9 +1,9 @@
# Link Protocol Specification (v2)
**Version:** 2 (`PACKET_VERSION 0x02`)
**Last Updated:** 2026-09-21
**Source of truth:** `include/protocol/automotive_data.h` — byte-identical in both repos.
**Direction:** Controller A (ESP32-S3-Touch-LCD-5B) → Controller B (ESP32-S3-LCD-1.3), one way.
**Last Updated:** 2026-09-27
**Source of truth:** `include/protocol/automotive_data.h` (+ `link_secure.h`) — byte-identical in both repos.
**Direction:** gauge data Controller A (ESP32-S3-Touch-LCD-5B) → Controller B (ESP32-S3-LCD-1.3). Since 2026-09-27 B answers with `STATUS` frames over ESP-NOW and A sends B maintenance frames (`PAIR` on the wire, `SECURE` over ESP-NOW) — see *Maintenance frames* below.
---
@@ -28,8 +28,8 @@ The same frames are sent on two paths at once. B accepts either and deduplicates
|---|---|---|
| start | 1 | `0xAA` |
| version | 1 | `0x02` — B rejects any other value (counted as version error) |
| type | 1 | `0x01` DATA, `0x02` CONFIG |
| length | 1 | payload bytes (21 for DATA, 27 for CONFIG) |
| type | 1 | `0x01` DATA, `0x02` CONFIG, `0x03` STATUS, `0x04` PAIR, `0x05` SECURE |
| length | 1 | payload bytes (21 DATA, 27 CONFIG, 78 STATUS, 42 PAIR, 29–160 SECURE); `PACKET_MAX_PAYLOAD` = 160 |
| payload | length | see below, little-endian, packed |
| checksum | 1 | XOR of version, type, length and every payload byte |
| end | 1 | `0x55` |
@@ -120,6 +120,18 @@ The same console also carries the OBD-II diagnostic probe (`diag pids | pid <hex
---
## Maintenance frames (2026-09-27) — for Controller B's firmware updates
`PACKET_VERSION` did not change: DATA and CONFIG are byte-identical, and a B built before these types counts them as type errors and carries on.
| Type | Direction | Transport | Payload | Purpose |
|---|---|---|---|---|
| `STATUS` 0x03 | B → A | ESP-NOW unicast to A's MAC (learned from A's data frames) | `link_status_t` (78 B): B's version, OTA phase (`LINK_OTA_*`, same numbering as A's `Ota::phase_t`), progress %, flags (paired / have Wi-Fi / joined / pending verify), `key_fp`, uptime, free heap, latest tag, message | every 5 s and on every phase change; A's Updates page "Controller B" card |
| `PAIR` 0x04 | A → B | **UART wire only** — B drops a PAIR heard by radio | `link_pair_t` (42 B): magic `"PAIR"`, 32-byte random key, A's STA MAC | `link pair` on A's console, sent 3×; both sides keep the key in NVS. The only secret in the system (both repos are public) |
| `SECURE` 0x05 | A → B | ESP-NOW unicast | `nonce[12] \| tag[16] \| AES-256-GCM(key, nonce, inner_type \| inner)` — helpers in `link_secure.h` | inner `LINK_INNER_OTA_CMD` 0x11 (`link_ota_cmd_t`: check / install [force] / rollback + random nonce, B ignores a repeat of the last 4) or `LINK_INNER_WIFI_CREDS` 0x12 (`link_wifi_creds_t`: SET/FORGET, ssid, pass). B also requires the sender MAC to be the paired A |
B reports `key_fp` = first two bytes of SHA-256(key) so A can tell "paired with my key" from "paired with an old one" and re-pair.
## Receiver behaviour (B)
- Link considered lost after 1000 ms without an applied DATA frame on any transport; display shows N/A and both gauge outputs go low.
@@ -131,7 +143,7 @@ The same console also carries the OBD-II diagnostic probe (`diag pids | pid <hex
## Changing the protocol
1. Edit `automotive_data.h` on A, bump `PACKET_VERSION`.
2. Copy the header to B unchanged.
1. Edit `automotive_data.h` on A. Bump `PACKET_VERSION` if DATA or CONFIG change; adding a new frame type does not need a bump (a stale B ignores unknown types).
2. Copy the header (and `link_secure.h`) to B unchanged (`cmp` them).
3. Update this document.
4. Flash both. A stale B logs version errors and applies nothing.