简体   繁体   中英

Bleak (python) does not respond on connect

I have found the correct Bluetooth address of the device I want to connect to. When I run the code below, it prints "Connecting to device..." but then hangs and never prints "Connected" or finishes running. No errors are thrown.

import asyncio
from bleak import BleakClient

address = "24:71:89:cc:09:05" # Replaced with actual bluetooth address

async def main(address):
    print("Connecting to device...")
    async with BleakClient(address) as client:
        print("Connected")

asyncio.run(main(address))

Is this issue related to my PC software/drivers? I am on a Lenovo laptop running Windows 11.

Or, do some devices not respond to simple "connection requests"? The device I am connecting to is a Tesla Model 3, and I know there is a particular set of data I should be sending to authenticate. If this is the case, how do I send data without connecting with a BleakClient in this way?

Update: I should mention that scanning / discovering devices works just fine via Bleak. And, I tried connecting to other devices via Bleak and the same issue occurred. Bluetooth through the Windows Settings app works fine though.

I was also having issues using any bleak commands beyond discover() . I downgraded from 0.14.3 to 0.14.0 and that resolved my problem.

When I looked up "python tesla bluetooth api" I found my way to this site , which documents the API which seems great for what you are doing. That lets you do lots of things like unlocking, opening trunk, etc.

It sounds like the main problem is that you can't connect at all in order to do stuff. The way that site is written glosses over that part, just saying "send it over".

I would ensure that you have the right address, you should use this scanning code from the Bleak doc . Also, make sure that you can use bluetooth normally, like by connecting to a wireless speaker.

Sadly, this error is still unsolved in Bleak, in the project they claim: still waiting for someone to capture bluetooth packets.

Trying to connect, you get either an endless hang with no response or if the device is paired upfront: Connection error: [WinError -2147483629] The object has been closed

It seems the Library isn't very mature for windows: https://github.com/hbldh/bleak/issues?q=label%3A%22Backend%3A+WinRT%22+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM