Skip to content

Give each fresh pod its own Bluetooth address - #37

Merged
ps2 merged 1 commit into
mainfrom
fix/random-address
Nov 25, 2026
Merged

ps2 merged 1 commit into
mainfrom
fix/random-address

Conversation

@marionbarker

Copy link
Copy Markdown

Ever since -mode o5 was added, switching the simulator between DASH and Omnipod 5 meant the phone wouldn't pair with the pod until its Bluetooth was turned off and on.

Both modes were served from the adapter's own address, with the same pod service but different data characteristics. A DASH uses …2442, and an Omnipod 5 uses …2443. iOS kept what it had cached for that address, so after a mode switch the phone still had the other mode's details. Turning Bluetooth off and on was the only thing that cleared it, and it always did. Other steps, including force-quitting Loop, didn't help, so the stale state was in iOS, not in the app.

A real pod has its own address, so this never comes up with real pods. Adding a Service Changed characteristic to the simulator's GATT server was tried first, and it didn't help.

Change

  • Each fresh pod gets its own address: -fresh gives the pod a random static Bluetooth address, saved in the state file as ble_address.
  • The simulator serves from that address: After opening the adapter, the simulator sets it to the pod's address with LE Set Random Address, then advertises from it. Opening the adapter resets it, which clears any random address, so the address is set after that and before the first advertisement. If the adapter refuses the address, the simulator stops with an error naming it.
  • Older state files keep working: A state file written before this change has no ble_address. That pod keeps the adapter's address, so a phone already paired with it still finds it. The log says so and suggests -fresh.
  • Log line: At startup the simulator logs which address it's using.
  • Unchanged: -transport impossible doesn't use the adapter, so it's unaffected.

Testing

  • Unit tests: go test ./pkg/bluetooth/ passes on the Pi, including new tests that generated addresses are valid random static addresses and differ, and that the parser rejects bad input.
  • With a phone: Ran the simulator from this branch on a Raspberry Pi with Loop.
    • After one Bluetooth cycle on the phone, switched between -mode dash -fresh and -mode o5 -fresh several times. Each pod paired without cycling Bluetooth.
    • Quit the simulator and restarted it without -fresh. Loop kept talking to the same pod.

🤖 Generated with Claude Code

A DASH and an Omnipod 5 were served from the adapter's own address, but with
different data characteristics. iOS kept what it had cached for that address,
so after a mode switch the phone wouldn't pair until its Bluetooth was turned
off and on.

A fresh pod now gets a random static address, saved in the state file. The
simulator sets the adapter to it after opening the device and advertises from
it, so the phone sees each fresh pod as a new device, as with real pods. A pod
from an older state file has no saved address and keeps the adapter's address,
so a phone already paired with it still finds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@marionbarker
marionbarker requested review from itsmojo and ps2 November 25, 2026 02:59

@itsmojo itsmojo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM and works in repeated tests. Nice to have this fixed!

@ps2
ps2 merged commit ebb18be into main Nov 25, 2026
1 check passed
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.

3 participants