Skip to content

fix: never start a scan window while MQTT is still sending - #12

Merged
mohanvd merged 2 commits into
mainfrom
fix/send-window-drain
Oct 27, 2026
Merged

mohanvd merged 2 commits into
mainfrom
fix/send-window-drain

Conversation

@mohanvd

@mohanvd mohanvd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

What this changes

Firmware 0.1.1:

  • SEND_WINDOW_MAX_MS goes from 300 to 500 ms.
  • A scan window never starts while the unit still has data in flight. If a send window has not drained by 500 ms, the unit keeps waiting and counts an overrun instead of scanning. After 5 s (SEND_OVERRUN_GIVE_UP_MS) it hands back to the reconnect checks, and the main loop still only starts a scan once MQTT has drained.
  • mqtt_link_drained() now also requires that TCP has no unacknowledged segments, so TCP has nothing it could resend during a scan.

Plus docs/results/2026-10-27-send-window-500/report.md, and docs/firmware.md updated for the new rule.

How it was tested

10 minutes on unit N1 in a crowded room (116 devices heard), see the report:

  • MQTT data no longer lands in scan windows. tx_in_scan was 3 in 600 s, all at the same 5-minute rhythm seen yesterday, one of them in a 10 s stretch with no overrun. So they are network housekeeping (probably ARP), not MQTT. Before, on 0.1.0, it was 6 in 10 s.
  • The cost at this load: 75 overruns, send windows up to 5 s, the unit scanned 53 % of the time, and BLE latency p95 was 4.6 s (13.4 % over 2 s). Design requirement 4 is not met at about 120 BLE advertisements a second. The report lists next steps (Nagle during send windows, less BLE data per message).
  • 0 dropped, 0 rejected in the window.
  • The nRF24L01 failed its boot self-check this morning (wiring), so there is no spectrum data in this run.
  • python -m pytest: 120 passed. The firmware builds locally. The firmware host tests run in CI (no host C compiler on this laptop). INVIGIL_DEBUG_RAW_ADDR is 0.

Checklist

  • Tests pass: python -m pytest
  • No raw data or secrets: no raw captures, MAC addresses, salts, Wi-Fi or MQTT credentials
  • Docs updated where behavior, commands or formats changed
  • Commit messages follow conventional commits (feat:, fix:, docs:, test:, chore:)
  • Nothing in this change makes the unit transmit

Raise the send window limit to 500 ms. When a send window has not drained by then, keep waiting and count an overrun instead of starting the next scan. Drained now also means the broker has acknowledged every TCP segment, so TCP has nothing left to resend during a scan. Firmware 0.1.1.
10 minutes in a crowded room on 0.1.1: MQTT no longer lands in scan windows, but send windows took up to 5 s and BLE latency p95 reached 4.6 s. The firmware docs describe the new send window rule.
@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 5:52am UTC

Request Review

@mohanvd
mohanvd merged commit b4c2b18 into main Oct 27, 2026
7 checks passed
@mohanvd
mohanvd deleted the fix/send-window-drain branch October 27, 2026 05:56

This branch was successfully deployed

1 active deployment
Preview — 06bc6c41 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