Skip to content

feat: support three simultaneous BLE controllers - #2

Closed
y52en wants to merge 2 commits into
mainfrom
agent/multi-controller
Closed

y52en wants to merge 2 commits into
mainfrom
agent/multi-controller

Conversation

@y52en

@y52en y52en commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • expose one ESP32-C3 as three independent Bluetooth LE controller identities
  • keep input, connection state, status, and rumble isolated per controller slot
  • support three simultaneous local/remote controllers in the host bridge and Cloudflare signaling layer
  • redesign the browser UI around three controller cards with clearer ownership, connection, and diagnostics states
  • preserve the existing 8-byte EasyCon packet by encoding the slot in two previously unused button bits

Firmware design

  • creates three legacy-format extended advertising sets
    • slot 1 uses the public address
    • slots 2 and 3 use deterministic random-static addresses
  • maintains independent HID controller instances, queues, tasks, runtime state, and rumble feedback
  • derives and shares the target LTK across the three local identities to match NimBLE's peer-address-keyed security store
  • raises ESP32-C3 NimBLE/controller limits for three connections, three bonds, advertising instances, activities, and CCCDs
  • adds robust handling for incomplete NVS bond records and advertising-buffer allocation failures
  • emits slot-scoped serial messages (DS:<slot>, DI:<slot>, and RV:<slot>)

Host, signaling, and UI

  • routes three controller states over serial with fair round-robin scheduling
  • tracks status and rumble per slot
  • allocates the first three remote guests to distinct slots; additional guests wait until a slot is released
  • supports host-controlled grant, release, and handoff
  • maintains three concurrent host WebRTC sessions and queues early ICE candidates
  • fixes an existing guest-peer mismatch
  • adds responsive controller cards, explicit join controls, ownership indicators, accessible labels, and collapsible diagnostics
  • validates loopback WebSocket origins

Validation

  • 38 Node.js host/UI/signaling tests
  • JavaScript syntax checks for host, browser app, and Worker
  • native multi-controller C test with -std=c11 -Wall -Wextra -Werror -pedantic
  • native C test under AddressSanitizer and UndefinedBehaviorSanitizer
  • public-tree text/secret check across 100 files
  • git diff --check
  • GitHub Actions ESP32-C3 build (headless and LCD profiles)
  • physical Switch 2 validation with three simultaneously paired controllers
  • physical reconnect and per-slot rumble validation

Hardware validation checklist

  1. Pair all three advertised controller identities from the Switch 2 controller screen.
  2. Confirm all three remain connected simultaneously.
  3. Exercise every slot independently and confirm no input leaks to another slot.
  4. Trigger rumble on each slot and confirm feedback reaches only its owning browser/controller card.
  5. Power-cycle the ESP32-C3 and verify all three identities reconnect.
  6. Remove one bond, pair that slot again, and verify the other two slots remain usable.

Notes

This PR is intentionally a draft until the three-controller hardware checklist is completed. A full local ESP-IDF firmware build was not available in the sandbox, so the repository's GitHub Actions builds are the authoritative compile check.

@y52en
y52en marked this pull request as ready for review August 20, 2026 09:43
@y52en y52en self-assigned this Aug 20, 2026
@y52en y52en closed this Aug 20, 2026
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