Skip to content

two_devices example does not work! #1197

Answered by dlech
Yaro-o asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, trying to connect to two devices at the same time is usually asking for trouble. Maybe something like this would be better?

async def connect_to_device(address, lock):
    print("starting", address, "loop")
    try:
        with lock:
            client = BleakClient(address, timeout=5.0)
            await client.connect()
        try:
            print("connected to", address)
            await client.start_notify(notify_uuid, callback)
            await asyncio.sleep(10.0)
        finally:
            await client.disconnect()
            print("disconnect from", address)
    except Exception as e:
        print(e)


async def main(addresses):
    lock = asyncio.Lock()
    return a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Yaro-o
Comment options

Answer selected by Yaro-o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants