question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?

https://github.com/hbldh/bleak/blob/08f4fc4cfb9b8c334b31d1e0ee76b6088684ec44/bleak/backends/corebluetooth/client.py#L63

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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dhalbertcommented, Jun 7, 2020

A discover has to have been called before maing any connect, that is why it is in connect to ensure that the native OS backend actually has the BLE device in its’ caches.

I encountered the same thing just today. As @niemyjski mentioned, if BleakClient() alternatively took a device instead of an address, it could assume the device had been recently discovered. The constructor could take either, and do a discover() only if an address were passed.

0reactions
hbldhcommented, Sep 25, 2020

This is fixed in release 0.8.0. Closing.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found