Skip to content

Add bondMode option to ConnectOptions for native BLE#123

Merged
microbit-grace merged 4 commits intoappsfrom
review-flow
Apr 27, 2026
Merged

Add bondMode option to ConnectOptions for native BLE#123
microbit-grace merged 4 commits intoappsfrom
review-flow

Conversation

@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor

@microbit-matt-hillsdon microbit-matt-hillsdon commented Mar 24, 2026

The native connect() flow previously assumed the caller intended to flash: after a new bond it always reset the device into pairing mode. This is wrong for two other common scenarios:

  1. BLE-enabled firmware, interact with services (sensors, UART, LEDs): The device should end up in application mode, not pairing mode. bondMode: "application" handles this — it still bonds if needed (required to get past the firmware whitelist on first connection) but resets to application mode instead of pairing mode.

  2. Open-link firmware, no bonding needed: bondMode: "none" skips createBond() on Android and the iOS pairing trigger entirely, avoiding an unnecessary pairing dialog and the 15s post-bond firmware reset.

The default for connect() is "pairing". flash() explicitly passes bondMode: "pairing" internally, so the flash flow is unchanged.

On web, bondMode is ignored — the browser manages pairing transparently via the OS when accessing encrypted characteristics (well, so Claude claims, we need more practical experience here). But either way we for sure can't trigger it.

The demo app gains a Bond mode selector (native Bluetooth only) to exercise all three modes.

Fixes #118

The native connect() flow previously assumed the caller intended to
flash: after a new bond it always reset the device into pairing mode.
This is wrong for two other common scenarios:

1. BLE-enabled firmware, interact with services (sensors, UART, LEDs):
   The device should end up in application mode, not pairing mode.
   bondMode: "application" handles this — it still bonds if needed
   (required to get past the firmware whitelist on first connection)
   but resets to application mode instead of pairing mode.

2. Open-link firmware, no bonding needed:
   bondMode: "none" skips createBond() on Android and the iOS pairing
   trigger entirely, avoiding an unnecessary pairing dialog and the
   15s post-bond firmware reset.

The default for connect() is now "application". flash() explicitly
passes bondMode: "pairing" internally, so the flash flow is unchanged.

On web, bondMode is ignored — the browser manages pairing transparently
via the OS when accessing encrypted characteristics.

The demo app gains a Bond mode selector (native Bluetooth only) to
exercise all three modes.

This is breaking for connect then flash scenarios over unknown firmware which
now need to pass bondMode: pairing.

Fixes #118
@microbit-matt-hillsdon
Copy link
Copy Markdown
Contributor Author

For discussion/experimentation rather than a quick review + merge.

@microbit-grace
Copy link
Copy Markdown
Contributor

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying microbit-connection with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7478515
Status:🚫  Build failed.

View logs

@microbit-grace
Copy link
Copy Markdown
Contributor

microbit-grace commented Apr 27, 2026

As discussed, changed the default from application bond mode to pairing bond mode. Played around in the demo app and it LGTM

I think this means it's not a breaking change anymore?

@microbit-grace microbit-grace self-requested a review April 27, 2026 13:34
@microbit-matt-hillsdon microbit-matt-hillsdon changed the title Breaking: Add bondMode option to ConnectOptions for native BLE Add bondMode option to ConnectOptions for native BLE Apr 27, 2026
@microbit-grace microbit-grace merged commit e70490a into apps Apr 27, 2026
3 of 4 checks passed
@microbit-grace microbit-grace deleted the review-flow branch April 27, 2026 13:35
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