Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing issue getting characteristics #52

Closed
matthewhague opened this issue Nov 29, 2018 · 3 comments
Closed

Timing issue getting characteristics #52

matthewhague opened this issue Nov 29, 2018 · 3 comments

Comments

@matthewhague
Copy link

matthewhague commented Nov 29, 2018

  • bleak version: 0.2.2
  • Python version: 3.7.1
  • Operating System: Arch Linux

Description

Attempting to print the available services. This fails because bleak has not yet discovered all services.

What I Did

Here is a simplified version of the code i am trying to run

async def print_services(mac_addr : str, loop : asyncio.AbstractEventLoop):
    async with BleakClient(mac_addr, loop=loop) as client:
        svcs = await client.get_services()
        print("Services:", svcs)

def do_thing(mac_addr : str):
    loop = asyncio.get_event_loop()
    loop.run_until_complete(print_services(mac_addr, loop))

The output is

    Services: {}

There should be many services. I can add a delay and get the right result:

async def print_services(mac_addr : str, loop : asyncio.AbstractEventLoop):
    async with BleakClient(mac_addr, loop=loop) as client:
        await asyncio.sleep(10)
        svcs = await client.get_services()
        print("Services:", svcs)

Which results in

Services: {'0000180a-0000-1000-8000-00805f9b34fb': {'UUID': '0000180a-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84', 'Primary': True, 'Includes': [], 'Path': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84/service0021'}, '00001000-0000-1000-8000-00805f9b34fb': {'UUID': '00001000-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84', 'Primary': True, 'Includes': [], 'Path': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84/service0010'}, '00001801-0000-1000-8000-00805f9b34fb': {'UUID': '00001801-0000-1000-8000-00805f9b34fb', 'Device': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84', 'Primary': True, 'Includes': [], 'Path': '/org/bluez/hci0/dev_F4_B8_5E_F3_B6_84/service000c'}}

Apologies if this is something i have not understood about the library.

@hbldh
Copy link
Owner

hbldh commented Nov 30, 2018

Hm, strange. I will look into this tonight.

@hbldh hbldh closed this as completed in 2409980 Nov 30, 2018
hbldh added a commit that referenced this issue Nov 30, 2018
Fixes #52 and #51.
@hbldh
Copy link
Owner

hbldh commented Nov 30, 2018

I think the modification I did in version 0.2.4 will solve the problem. I could not reproduce it by your scripts in Ubuntu 18.04 installation, but I think I had misplaced the checking of the property "ServicesResolved" in getting services so this might solve your problem. Try it out and report back here.

@matthewhague
Copy link
Author

Seems to work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants