Closed dolors-1210 closed 3 years ago
Hello,
It seems like the await BleakScanner.find_device_by_address
call could not find your device, so a None
was returned. The example could be improved there. It should be something like this:
"""
Connect by BLEDevice
"""
import asyncio
import platform
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError
async def print_services(ble_address: str):
device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
if not device:
raise BleakError(f"A device with address {ble_address} could not be found.")
async with BleakClient(device) as client:
svcs = await client.get_services()
print("Services:")
for service in svcs:
print(service)
ble_address = (
"24:71:89:cc:09:05"
if platform.system() != "Darwin"
else "B9EA5233-37EF-4DD6-87A8-2A875E821C46"
)
loop = asyncio.get_event_loop()
loop.run_until_complete(print_services(ble_address))
Connecting to phones have often caused problems with Bleak. Sometimes they require pairing, so you will have to experiment some with getting it to work. Anyway, try increasing the timeout
from the default 10 seconds to maybe 20 for the discovery part (I have done this in the example above)
Also try to use the service_explorer.py
example instead. It is more verbose and well tested.
A new release of Bleak was just done, version 0.11.0. I recommend upgrading to that since there are some critical fixes for the Windows backend.
Description
Hi, it's Lola! I developed a code using bleak module in Linux and when I imported the code in a Windows machine, the code did not work. It's like bleakScanner is working but not bleakClient.
What I Did
I made some checkings with simple code extracted from the git examples and that was my results:
discover.py: this code is working for Windows:
connect_by_bledevice.py: this code is not working for Windows but is working for Linux. I replaced the mac_addr field for the mac_addr of my phone and the phone had the bluetooth enabled.
The errors I'm getting are the following:
Please if you know what happens just let me know.
Thanks!
Lola