-
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
Problem with connecting to a few devices #105
Comments
Can you try to connect to two devices in macOS using two different terminals and see if that works. If so, then there is a limitation in the bleak macOS backend that needs to be documented. See this for similar problem: https://stackoverflow.com/questions/34787976/how-can-i-implement-core-bluetooth-functionality-for-multiple-devices |
It took me a while 😀 I did what you said. Bleak connects correctly to two devices at two different terminals. Unfortunately with one terminal, just like in my example, it stops before |
Ok. I will add a note about this in the documentation for the time being. This issue is beyond the scope of my available time to address. |
This is solved in the last The following code should now work: from bleak import BleakClient
import asyncio
notify_uuid = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(0xffe1)
def callback(sender, data):
print(sender, data)
def run(addresses):
loop = asyncio.get_event_loop()
tasks = asyncio.gather(
*(connect_to_device(address, loop) for address in addresses)
)
loop.run_until_complete(tasks)
async def connect_to_device(address, loop):
print("starting", address, "loop")
async with BleakClient(address, loop=loop, timeout=10.0) as client:
print("connect to", address)
try:
await client.start_notify(notify_uuid, callback)
await asyncio.sleep(10.0, loop=loop)
await client.stop_notify(notify_uuid)
except Exception as e:
print(e)
print("disconnect from", address)
if __name__ == "__main__":
run(["B9EA5233-37EF-4DD6-87A8-2A875E821C46", "F0CBEBD3-299B-4139-A9FC-44618C720157" ]) |
Description
I would like to connect with bleak to a few devices at the same moment and in one terminal. I use loop.create_task() and on windows everything works fine, my two devices notifing perfectly. On Mac os one device also works great but if I try to connect two devices, my devices show that they are connected but they are not notifing. I debug my program and devices get in connect _to_device but print() in 'async with BleakClient() don't show.
The text was updated successfully, but these errors were encountered: