Stream slave accel via ESP-NOW with master snapshot cache.
Slaves push BMA456 samples at 16ms when enabled; the master caches per client and exposes ACCEL_SNAPSHOT and ACCEL_STREAM over UART. goTool adds dashboard stream controls, HTTP accel-stream routes, and an external WebSocket API with per-connection receive/interval and slave stream commands. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+12
-11
@@ -115,6 +115,7 @@ Schema: `proto/esp_now_messages.proto`. Encode/decode: `esp_now_proto.c`. The ES
|
||||
| `ESPNOW_UNICAST_TEST` | Master → slave | `EspNowUnicastTest` (`seq`) |
|
||||
| `ESPNOW_FIND_ME` | Master → slave | `EspNowFindMe` (`client_id` filter) — LED locate sequence |
|
||||
| `ESPNOW_RESTART` | Master → slave | `EspNowRestart` (`client_id` filter) — reboot slave |
|
||||
| `ESPNOW_ACCEL_SAMPLE` | Slave → master | `EspNowAccelSample` (`slave_id`, `x`, `y`, `z` raw LSB) — ~every 16 ms |
|
||||
| `ESPNOW_OTA_START` | Master → slave (unicast) | `EspNowOtaStart` (`total_size`) |
|
||||
| `ESPNOW_OTA_PAYLOAD` | Master → slave | `EspNowOtaPayload` (`seq`, up to 200 B `data`) |
|
||||
| `ESPNOW_OTA_END` | Master → slave | `EspNowOtaEnd` |
|
||||
@@ -217,7 +218,7 @@ Host and master speak nanopb-encoded `UartMessage` inside UART frames (byte 0 =
|
||||
| 21 | `OTA_SLAVE_PROGRESS` | Implemented (`cmd/cmd_ota_slave_progress.c`) — query per-slave ESP-NOW OTA progress |
|
||||
| 22 | `FIND_ME` | Implemented (`cmd/cmd_espnow_find_me.c`) — `client_id=0` local ring, `>0` ESP-NOW to slave |
|
||||
| 23 | `RESTART` | Implemented (`cmd/cmd_restart.c`) — `client_id=0` reboot master, `>0` ESP-NOW reboot slave |
|
||||
| 24 | `ACCEL_READ` | Implemented (`cmd/cmd_accel_read.c`) — on-demand BMA456 XYZ (raw LSB) |
|
||||
| 24 | `ACCEL_SNAPSHOT` | Implemented (`cmd/cmd_accel_snapshot.c`) — cached slave accel from ESP-NOW stream |
|
||||
|
||||
Regenerate C code:
|
||||
|
||||
@@ -311,20 +312,20 @@ Sets the **software** deadzone used by `bosch456.c` when logging accel (see [BMA
|
||||
|
||||
**Response:** `accel_deadzone_response` with applied `deadzone`, `success`, and `slaves_updated` (ESP-NOW count).
|
||||
|
||||
### ACCEL_READ command
|
||||
### ACCEL_SNAPSHOT command
|
||||
|
||||
Read the **current** BMA456 accelerometer sample on this node (master or slave with sensor). Values are raw LSB in the configured **±2g** range; they are **not** filtered by the software deadzone (unlike periodic `ACC X=…` logs in `bosch456.c`).
|
||||
Read **cached** accelerometer samples on the **master** (one entry per registered slave). Slaves send `ESPNOW_ACCEL_SAMPLE` to the master every **16 ms** (`esp_now_comm.c`); the master stores the latest value per client in `client_registry.c`.
|
||||
|
||||
**Request:** framed `18` (`0x18`) only, or `18` + empty `accel_read_request`.
|
||||
**Request:** framed `18` (`0x18`) + optional `accel_snapshot_request` (`client_id`: `0` = all slaves, `>0` = one id).
|
||||
|
||||
**Response:** `accel_read_response`:
|
||||
**Response:** `accel_snapshot_response.samples[]`:
|
||||
|
||||
| Field | Meaning |
|
||||
|-------|---------|
|
||||
| `success` | `true` if BMA456 is ready and I2C read succeeded |
|
||||
| `x`, `y`, `z` | Raw accel LSB (`sint32`; meaningful only when `success`) |
|
||||
|
||||
If the sensor was not probed at boot (`bma456_is_ready()` false), `success` is `false` and axes are zero.
|
||||
| `client_id` | Slave id (registry) |
|
||||
| `valid` | At least one ESP-NOW sample received since boot |
|
||||
| `x`, `y`, `z` | Raw BMA456 LSB (±2g) |
|
||||
| `age_ms` | Ms since last sample from that slave |
|
||||
|
||||
Host:
|
||||
|
||||
@@ -332,7 +333,7 @@ Host:
|
||||
go run . -port /dev/ttyUSB0 accel
|
||||
```
|
||||
|
||||
Implementation: `bma456_read_accel()` in `bosch456.c` (mutex with the 10 Hz poll task), handler in `cmd/cmd_accel_read.c`.
|
||||
External API (`serve -api-addr :8081`) polls this command every 16 ms and streams JSON over WebSocket.
|
||||
|
||||
### ESPNOW_UNICAST_TEST command
|
||||
|
||||
@@ -479,7 +480,7 @@ Target: ESP32-S3. Close serial monitor on the UART adapter port before running `
|
||||
| `cmd/cmd_client_info.c/h` | CLIENT_INFO handler |
|
||||
| `client_registry.c/h` | Registered slave table |
|
||||
| `bosch456.c/h` | BMA456H I2C driver, accel poll, on-demand read, tap INT, deadzone filter |
|
||||
| `cmd/cmd_accel_read.c` | UART `ACCEL_READ` — current accel XYZ |
|
||||
| `cmd/cmd_accel_snapshot.c` | UART `ACCEL_SNAPSHOT` — cached slave accel |
|
||||
| `board_input.c/h` | Taster GPIO12, LiPo ADC on GPIO1 / GPIO12 |
|
||||
| `pod_settings.c/h` | NVS persistence (accel deadzone, …) |
|
||||
| `led_ring.c/h` | LED ring (digit display, progress bar) |
|
||||
|
||||
Reference in New Issue
Block a user