Skip to content

reserve the attach-protocol wire format for the sensor-sync bus - #13

Merged
aphelps-claude-bot merged 1 commit into
base-wled-16.0.1from
m3c-attach-failover
Jul 30, 2026
Merged

aphelps-claude-bot merged 1 commit into
base-wled-16.0.1from
m3c-attach-failover

Conversation

@aphelps-claude-bot

@aphelps-claude-bot aphelps-claude-bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Part of aphelps/WLED_dev#23 in the parent repo.

Summary

The backbone router gains an attach protocol: routers advertise their distance to the timebase leader, nodes bind to the one they rank best, and the router acks with a membership lease. Three of those frames cross between the router firmware and the WLED edge, so their numbers and payload layouts have to be agreed here rather than in the router repo.

Adds to sensor_sync_protocol.h:

  • msgType numbers SENSOR_SYNC_MSG_ROUTER_ADV (2), SENSOR_SYNC_MSG_ATTACH (3), SENSOR_SYNC_MSG_ATTACH_ACK (4).
  • Payload structs RouterAdvert{leaderId, leaderTerm, hopCost, memberCount}, NodeAttach{routerId}, AttachAck{nodeId, leaseMs}, and SS_HOP_UNREACHABLE.
  • The convention those numbers establish: SNAPSHOT is the only type that travels multi-hop; everything above it is a single-hop control frame consumed by whichever node hears it.

The selection and membership logic stays in the router repo (esp-now-router/src/router_attach.h) — the edge never calls it. Only the wire format is shared, matching how router_relay.h / router_election.h are already split.

Additive only. No existing header or payload field moves, ss_parse_header still accepts only SNAPSHOT, and the wire version stays 5 — existing devices interoperate unchanged.

SENSOR_SYNC.md is updated in the same change, per its own maintenance rule.

Submodule PRs

Test plan

Automated:

  • make test (from the WLED_dev super-repo) — the ampworks dispatch + ring suites still pass against the changed header
== WLED ampworks host tests ==
-- sensor_sync_test --      ALL TESTS PASSED
-- sensor_sync_ring_test -- ALL TESTS PASSED
  • pio run -e ampworks
RAM: 25.3% (82896 / 327680)   Flash: 83.3% (1310205 / 1572864)   [SUCCESS]
  • cd esp-now-router && pio run -e wt32-eth01 — the router builds against the same header
RAM: 12.8% (41888 / 327680)   Flash: 44.2% (579157 / 1310720)   [SUCCESS]
  • cd esp-now-router && pio test -e native — relay / election / attach host suites all pass

No manual testing for this PR on its own; the hardware verification is tracked on the parent PR.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review (bot) of the shared wire-format reservation at head 56d4c56.

Wire-format discipline verified against the code:

  • The header gains only numbers and packed payload structs that both sides parse off the wire (RouterAdvert/NodeAttach/AttachAck, SS_HOP_UNREACHABLE, msgType 2/3/4) — no selection, membership, or timer logic leaked in. The membership table and route selection live in esp-now-router/src/router_attach.h as the banner says.
  • msgType 2/3/4 collide with nothing (SNAPSHOT=0, BEACON=1), and the edge rejects every non-snapshot type via ss_parse_header's msgType != SENSOR_SYNC_MSG_SNAPSHOT check — confirmed at head, so the new control frames cannot reach edge dispatch.

Cross-repo note: RouterAdvert.leaderTerm's field comment calls it a "stale-advert guard", but the router-side selection never reads it — see the companion review on aphelps/esp-now-router#2 for the fix options; whichever way that lands, this comment should match.

One scope finding inline (medium).

Comment thread usermods/ampworks/SENSOR_SYNC.md Resolved

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review (bot) of 56d4c56..627ea13 — one docs commit.

  • Prior medium (scope: edge side not implemented, docs silent about it) — addressed. The new SENSOR_SYNC.md paragraph states the reservation explicitly, and its claim is verified against head: ss_parse_header accepts SENSOR_SYNC_MSG_SNAPSHOT alone (the msgType != SENSOR_SYNC_MSG_SNAPSHOT reject), so edges do ignore msgType 2–4 and the handshake runs router-to-router as described.
  • Prior cross-repo note (RouterAdvert.leaderTerm documented as a "stale-advert guard" but never consulted) — resolved on the other side. esp-now-router#2's 64dc581 now gates route selection on leaderTerm via ss_seq_newer, so this header's comment is accurate as written; no change needed here.
  • New (introduced by the companion router commit): the NodeAttach.routerId wildcard comment is now wrong — inline, minor.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review (bot) of 627ea13..c88a3c46 — a single comment line, the fix for the prior minor.

  • Prior minor (NodeAttach.routerId comment still documented the removed 0 = any router wildcard) — fixed. The comment now reads "must name one router, never 0", which matches router behaviour at esp-now-router 08bd6e2 on both sides of the wire: the receiver admits an attach only when n.routerId == selfId (no wildcard branch remains in attachHandleFrame), and the sender can only emit an attach while a route is held (sendAttach is reached only with route.routerId != 0), so 0 is never put on the wire either. Wire contract and implementation agree.

Nothing else in the range; clean.

Add the msgType numbers and payload structs for the router attach handshake
(RouterAdvert, NodeAttach, AttachAck) so both sides of the mesh agree on the
format. The logic that uses them lives in the esp-now-router repo; this repo
only reserves the format, and ss_parse_header still accepts snapshots alone,
so a WLED edge ignores these frames rather than acting on them. Reserving the
numbers here keeps a future edge client from colliding with them.
@aphelps-claude-bot
aphelps-claude-bot merged commit 586c613 into base-wled-16.0.1 Jul 30, 2026
2 checks passed
@aphelps-claude-bot
aphelps-claude-bot deleted the m3c-attach-failover branch July 30, 2026 07:26
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.

2 participants