bluetooth icon indicating copy to clipboard operation
bluetooth copied to clipboard

How to select a secondary adapter?

Open evilsocket opened this issue 1 year ago • 8 comments
trafficstars

Hi, I've tried to look into the code and the other open issues but I couldn't find a solution to this. Some machines might have multiple bluetooth adapters, however every example only uses bluetooth.DefaultAdapter.

I could not find a way to select another adapter in the system.

evilsocket avatar Aug 14 '24 11:08 evilsocket

Can you create an Adapter struct with the id field set to the device you want?

larkwiot avatar Dec 03 '24 04:12 larkwiot

Not on macOS https://github.com/tinygo-org/bluetooth/blob/release/adapter_darwin.go#L12

evilsocket avatar Dec 03 '24 10:12 evilsocket

This https://github.com/tinygo-org/bluetooth/pull/303 added ability to choose adapter on Linux.

Still no way to do this on any other platforms.

deadprogram avatar Jan 10 '25 08:01 deadprogram

@evilsocket i don't have a mac device that has multiple ble adapters. do you know a way to test https://github.com/tinygo-org/bluetooth/pull/348 to see if it fixes your issue?

hu13 avatar Feb 23 '25 20:02 hu13

sorry i got a head of myself. the macOS core/bluetooth api does not seem to support connecting to a specific bluetooth adapter by its macAddress.

hu13 avatar Feb 23 '25 21:02 hu13

understood, i guess it makes sense since you can't use external adapters on macOS

evilsocket avatar Feb 24 '25 11:02 evilsocket

https://github.com/tinygo-org/bluetooth/pull/303 allows this for Linux. However macOS is very restrictive.

Seems like the question has been answered. Can this issue be closed now?

deadprogram avatar Mar 05 '25 16:03 deadprogram

understood, i guess it makes sense since you can't use external adapters on macOS

You can use external adapters on macOS (the OS itself will switch which one is the main one). It just requires plugging the adapter in and rebooting or logging in and logging out.

Although if you wanted to control which adapter is used directly and potentially allow yourself to use a different one than the current primary OS-selected adapter you would need to interact with the device at the HCI level and bypass CoreBluetooth, which might be outside the scope of this library (most projects I knew of that did this have since dropped that approach or are unmaintained).

ansoni-san avatar Mar 05 '25 19:03 ansoni-san