IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.61k stars 490 forks source link

Select a host Bluetooth device (the one that starts the connection) #496

Closed toncho11 closed 2 years ago

toncho11 commented 2 years ago

Hi,

Is it possible to select between multiple USB plugged host Bluetooth devices? On my computer I have several Bluetooth devices and I want to initiate a connection from a specific one towards another Bluetooth device. How can I do that?

I think devices are enumerated: hci0 , hci1 ... I do not want to shutdown the not used device, just select another one.

toncho11 commented 2 years ago

I think I found it:

http://ianharvey.github.io/bluepy-doc/peripheral.html?highlight=peripheral

In the class Peripheral we can select which device we would like to use: On Linux, 0 means /dev/hci0, 1 means /dev/hci1 and so on.

kg-meso commented 1 year ago

Did this work for you? I am running bluepy on Raspbian and there is no /dev/hciX so setting the iface value does not affect which bluetooth device initiates the connection. See my issue #501. If you got it to work, do you mind sharing what OS you are using?

toncho11 commented 1 year ago

I got it running on Linux x86-64, actually on WSL2 (which requires a lot of extra effort). I modified https://github.com/toncho11/pyparrot to use more than 1 Bluetooth device. You need to search for hci devices with dmesg command. Kernel messages about hci devices should appear when you plug them in.

kg-meso commented 1 year ago

Interesting, I am able to see both of these devices as hci devices with specific hciX id's. Perhaps this codebase does not work well with Raspbian? If you call the command 'ls /dev/hci*' do you actually see hciX id's?

toncho11 commented 1 year ago

Sorry I do not have access right now.

kg-meso commented 1 year ago

No problem, can you recall what distro you were using? I was thinking of trying this code on Ubuntu.

toncho11 commented 1 year ago

I use WSL2 (Windows Subsystem for Linux), but you need many things to get Bluetooth working on it. Ubuntu should be OK.