Skip to content

feat: batch BLE readings into one message per send window - #13

Merged
mohanvd merged 2 commits into
mainfrom
feat/ble-batches
Oct 27, 2026
Merged

mohanvd merged 2 commits into
mainfrom
feat/ble-batches

Conversation

@mohanvd

@mohanvd mohanvd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

The unit now sends the BLE readings from each scan window together instead of one MQTT message per advertisement:

invigil/node/{node}/ble
{ "ts": <end of scan window>, "node": "N1", "readings": [ { "ts": ..., "addr": ..., "rssi": ..., "mfr": ... }, ... ] }

Each reading keeps exactly the old fields and rules. A message is split when it would go over 1400 bytes: with the MQTT header and topic that fits one TCP segment (MSS 1460), lwIP's MQTT output buffer (now 8 KB) holds several at once, and Mosquitto, paho and the browser client have no limit near it. The worst-case reading is 69 bytes, so a message carries at least 19 readings. Details in docs/contract.md.

Changes

  • docs/contract.md: new ble format, field tables, the size limit and why.
  • server/contract.py: validates batches and each reading; adds ble_rows(), pack_ble() and encode().
  • Logger: still one ble.csv row per reading, same columns, latency from each reading's own ts.
  • Fake publisher, dashboard demo source and store: same format; the store counts readings.
  • Launcher status: the BLE rate counts readings, not messages.
  • ml/: only synth.py, which validated single readings.
  • Firmware 0.2.0: batch builder in portable/payload.c, ble_ring_peek_at(), MQTT_OUTPUT_RINGBUF_SIZE 8192, ble_msgs in the summary line. Host tests cover the format, the off-contract checks and the size limit, and check_contract.py checks the samples against the limit.

Hardware result

10 minutes in the same crowded room as the send-window-500 run (docs/results/2026-10-27-ble-batches/report.md):

0.2.0 0.1.1
BLE messages a second 4.2 about 67
Time spent scanning 85 % 53 %
Longest send window per 10 s, median 170 ms 2,138 ms
BLE latency p95 1,025 ms 4,604 ms
BLE readings over 2 s 1.16 % 13.4 %
tx_in_scan 1 3
Rejected by the logger 0 0

The nRF24L01 still fails its self-check (wiring), so the run has no spectrum.

Tests

  • python -m pytest: 139 passed.
  • Dashboard: typecheck, lint, 61 tests and build pass.
  • Firmware builds for pico2_w with no warnings. The host C tests were only compile-checked locally (no PC compiler on this laptop); CI runs them.

The unit now sends the readings from each scan window together on
invigil/node/{node}/ble instead of one message per advertisement:
{ "ts": <end of scan window>, "node": "N1", "readings": [...] }.
Each reading keeps its own ts, addr, rssi and mfr with the same rules.
A message is split when it would go over 1400 bytes, so it fits one
TCP segment and several fit lwIP's MQTT output buffer at once.

- docs/contract.md: new ble format, field tables and the size limit.
- server/contract.py: validates batches, adds ble_rows() and pack_ble().
- Logger still writes one ble.csv row per reading, same columns.
- Fake publisher, dashboard demo source and store use the new format.
- Launcher status counts BLE readings, not messages.
- Firmware 0.2.0: batch builder in portable/payload.c, ring peek_at,
  MQTT output buffer 8 KB, ble_msgs in the summary line, host tests
  and the contract check cover the size limit.
- Results of a 10-minute crowded-room run in docs/results/.
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
invigil-demo Ready Ready Preview Oct 27, 2026 7:50am UTC

Request Review

@mohanvd
mohanvd merged commit b00f88f into main Oct 27, 2026
7 checks passed
@mohanvd
mohanvd deleted the feat/ble-batches branch October 27, 2026 07:54

This branch was successfully deployed

1 active deployment
Preview — 0c8710f0 Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant