Skip to content

Allow two Bluetooth hosts.#453

Merged
laurensvalk merged 7 commits intomasterfrom
multi-host
Jan 21, 2026
Merged

Allow two Bluetooth hosts.#453
laurensvalk merged 7 commits intomasterfrom
multi-host

Conversation

@laurensvalk
Copy link
Member

@laurensvalk laurensvalk commented Jan 15, 2026

This allows up to two Bluetooth host connections on Spike, which is needed for some upcoming applications. It also makes the existing support for simultaneous USB/BLE explicit. Until now, you'd have to connect BLE first, and then USB to make it work. Now you can do it in any order.

Ongoing work:

  • Cleanly close host connections on power down
  • Needs testing on Essential Hub and BLE only hubs as a sanity check

We'll still want to protect new downloads being started while another is in progress. But that was already an issue before this PR since you could have USB and BLE connected at the same time. See pybricks/support#2551.

This is helpful for the UI, which needs to wait for connection changes, and
checking multiple connection states for change may not be reliable if more than one changes at once.
We will allow simultaneous Bluetooth and USB connections, so it no longer makes sense to have USB override other states.

Advertising takes priority since it is a temporary state.

BLE and USB have equal priority, and we mix their color if both are connected.
Otherwise we never get the completion command, so this task keeps waiting.

This lets the UI call the start advertising command safely in any state.
This was already supported implicitly by connecting to Bluetooth first and then plugging in USB. It is more intuitive if we could just enable BLE advertising using the bluetooth button even if USB is already connected.
We had already split off the peripheral since it has more than one instance. The same will now apply to the host. The check for LE connections without Pybricks was never used, and NUS is not supported, so this function can go.
This allows using a secondary device like a phone to monitor the connection.
@coveralls
Copy link

coveralls commented Jan 15, 2026

Coverage Status

coverage: 49.86% (-0.01%) from 49.87%
when pulling e1850c1 on multi-host
into 5df8453 on master.

@laurensvalk laurensvalk merged commit e1850c1 into master Jan 21, 2026
34 checks passed
@dlech dlech deleted the multi-host branch January 21, 2026 15:16
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