Connecting via BleakClient with address does an additional discovery.
See original GitHub issue- bleak version: latest
- Python version: 3.8
- Operating System: macOS
- BlueZ version (
bluetoothctl -v
) in case of Linux:
Description
I noticed it was taking about 5 seconds to discover devices and then connect to a discovered device (another 5 seconds)… After looking at the code it appears that the client implementation does a second discovery which is painfully slow. Is there any way we can just pass in a populated device or just connect to the uuid directly instead of rediscovering?
What I Did
async def discoverDevice() -> BLEDevice:
devices = await discover()
for d in devices:
name = d.details.name()
if name is not None and "TEST" in name:
return d
return None
async def run(loop):
device = await discoverDevice()
if device is None:
return int(-1)
# this does another discovery..
async with BleakClient(device.address, loop=loop) as client:
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to use the bleak.BleakClient function in bleak - Snyk
To help you get started, we've selected a few bleak. ... addHandler(h) async with BleakClient(address, loop=loop) as client: x = await client.is_connected() ...
Read more >Linux backend — bleak 0.20.0a1 documentation
You can use ConnectDevice method if you already know the MAC address of the device. Else you need to StartDiscovery, Trust, Pair and...
Read more >bleak 0.11.0 - PyPI
To discover Bluetooth devices that can be connected to: ... import asyncio from bleak import BleakClient address = "24:71:89:cc:09:05" MODEL_NBR_UUID ...
Read more >bleak Changelog - PyUp.io
Added ``BleakClient.unpair()`` implementation for BlueZ backend. ... The BlueZ D-Bus backend will not avoid trying to connect to devices that are already ...
Read more >Core Bluetooth Characteristic Valu… | Apple Developer Forums
Connect to a peripheral calling centralManager(didConnect) which calls peripheral. ... client = BleakClient(device.address) try: await client.connect() svcs ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encountered the same thing just today. As @niemyjski mentioned, if
BleakClient()
alternatively took adevice
instead of an address, it could assume the device had been recently discovered. The constructor could take either, and do adiscover()
only if an address were passed.This is fixed in release 0.8.0. Closing.