python connecting to ble device with passkey using bleak

Viewed 283

I'm trying to connect to a ble device with bleak that uses a passkey.

async def connect(self, address):
    print("Connecting to device...")
    async with BleakClient(address) as client:
        response = await client.connect()
        print(response)

i'm using above code. The device displays the passkey to enter and windows displays the add a device message to input the code, but i get a timeout error from asyncio and never recieve the response to python.

Traceback (most recent call last):
  File "C:\Users\halmelam\PycharmProjects\read_passcode\main.py", line 137, in <module>
    asyncio.run(pair.connect(device.address))
  File "C:\Users\halmelam\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\halmelam\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\halmelam\PycharmProjects\read_passcode\main.py", line 95, in connect
    response = await client.connect()
  File "C:\Users\halmelam\.virtualenvs\read_passcode\lib\site-packages\bleak\backends\winrt\client.py", line 249, in connect
    await asyncio.wait_for(event.wait(), timeout=timeout)
  File "C:\Users\halmelam\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

How do I get the response and how can i send the passkey via python?

0 Answers
Related