-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only single client connects on Linux #618
Comments
A more up-to-date version of the example is here. However, we should probably update it to use a separate |
Here is an example: #551 (comment). Although it seems there are potentially issues with connecting and scanning at the same time that need to be resolved as well. |
Thanks for the very fast response. The code from the linked example didn't work, it resulted in the same output as the previous code I had.
I tried the code that you posted as causing the issue in 551 and got similar results again.
Only the second output file had any data; Using the code you linked to, where the scanner spawns monitor tasks worked a treat.
I'm slightly confused how the last example works but the others don't but I have some workable code for now. Thanks for the help. |
Having looked at the code with the scanner and played around with some of the synchronisation. It looks as though two I had to use two separate callbacks though because the from bleak import BleakClient
import asyncio
temperatureUUID = "45366e80-cf3a-11e1-9ab4-0002a5d5c51b"
ecgUUID = "46366e80-cf3a-11e1-9ab4-0002a5d5c51b"
notify_uuid = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(0x2A5B)
def callback1(sender, data):
print("1", data)
def callback2(sender, data):
print("2", data)
async def connect_first(w):
address = "D0:CD:84:98:C2:CC"
print("starting", address, "loop")
async with BleakClient(address, timeout=5.0) as client:
print("connect to", address)
try:
w.set()
await client.start_notify(notify_uuid, callback1)
await asyncio.sleep(10)
await client.stop_notify(notify_uuid)
except Exception as e:
print(e)
print("disconnect from", address)
async def connect_second(w):
await w.wait()
address = "D9:06:88:2B:8A:28"
print("starting", address, "loop")
async with BleakClient(address, timeout=5.0) as client:
print("connect to", address)
try:
await client.start_notify(notify_uuid, callback2)
await asyncio.sleep(10)
await client.stop_notify(notify_uuid)
except Exception as e:
print(e)
print("disconnect from", address)
async def run():
w = asyncio.Event()
asyncio.create_task(connect_first(w))
asyncio.create_task(connect_second(w))
await asyncio.Event().wait()
if __name__ == "__main__":
asyncio.run(run()) Give the following output
|
what happens if you run scanner first to find the devices, and connect using the BleDevice object of the found devices. It could be the "automagic" scanning done by the client that does'nt work. |
Run the scanner first, get the two |
Thanks for the help. I've built up around the |
Sounds like this issue has been resolved. |
Description
I am trying to connect to multiple Bluetooth devices in a single thread but only one connects and notifies. The other seems to hang indefinitely.
What I Did
I have followed issue #105 and tried the code in this comment (#105 (comment)). This didn't work. I get a "starting xxx loop" message for each address then only see a single "connect" message and notifications for one of the devices (seemingly at random as to which one it is). I have also verified that running in separate terminals works as expected. Thanks
The text was updated successfully, but these errors were encountered: