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.

Same script working only on some computers

See original GitHub issue
  • bleak version: 0.12.1
  • Python version: 3.8.5 (or 3.9)
  • Operating System: Windows 10

Description

I’m using bleak to connect a medical device (Heart Rate Monitoring mainly) in BLE to computers and receive the measurements.

I wrote a small script to do this and this worked on my computer. My model is a ASUS Vivobook 14 X405UA.

After this, I tried the script on another computer, this model is a Dell Inspiron 15 3505. On this computer the script worked well for 5 days after which it started to missbehave and then almost not work at all. I suspect a windows update changed something to this computer maybe related to the Bluetooth driver. I rebooted the computer and reinstalled visual studio, python, bleak from scratch and I’m still getting errors.

My issue is to understand why the script is not working anymore on the Dell.

What I Did

This is not exactly the script I’m using as I’m in fact reading from two characteristics and writing to another one but the structure in terms of Bleak and asyncio usage is the same, if needed I can provide a more complete code.

import asyncio
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError

# Variables
hr_uuid = "0aad7ea0-0d60-11e2-8e3c-0002a5d5c51b"
ADDRESS = "AA:AA:AA:AA:AA:AA"

def handler(sender, data):
    """Simple notification handler which prints the data received."""
    print(data)

async def run(address):
    device = await BleakScanner.find_device_by_address(ADDRESS, timeout=30.0)
    if not device:
        raise BleakError(f"A device with address {ADDRESS} could not be found.")
    async with BleakClient(device, timeout=30.0) as client:
        await client.start_notify(hr_uuid, handler)
        await asyncio.sleep(10.0)
        await client.stop_notify(hr_uuid)
        await client.disconnect()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run(ADDRESS))

So on my computer this still works fine, I can connect to the device, receive notifications, read them and disconnect properly. On the dell computer I got mainly one error (I tried the script in pyzo and visual studio code) , here’s the traceback in Pyzo :

Traceback (most recent call last):
  File "C:\Users\Script.py", line 178, in <module>
    loop.run_until_complete(run(ADDRESS))
  File "C:\Program Files\pyzo\source\pyzo\pyzokernel\guiintegration.py", line 209, in stub_run_until_complete
    return self.app._original_run_until_complete(*args)
  File "c:\users\user\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\Script.py", line 134, in run
    await client.start_notify(hr_uuid, handler)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\bleak\backends\winrt\client.py", line 773, in start_notify
    status = await characteristic_obj.write_client_characteristic_configuration_descriptor_async(
RuntimeError

The device connects to the computer but has an issue with the notification function. So the error is in start notify, and particularly in the line 773 of winrt\client.py (I slightly modified the paths of the traceback but the important is the one mentioned before). I suppose this is linked to the windows wrt backend but I am not sure how to fix this.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dlechcommented, Oct 27, 2021

You could also research the “Unreachable” error in relation to Windows Bluetooth Low Energy and see if that gives any hints.

Not sure if it is helpful, but this gives some explanation: https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/gatt-client#connecting-to-the-device

0reactions
lrq3000commented, Nov 25, 2021

Fixed the issue, it was because Windows was paired with the device, it works now that I unpaired them. I also used this free Microsoft tool to debug, maybe this can be helpful to OP. If this tool cannot connect either, then the issue is with the device or the pairing between the computer and the device, but not Bleak, since the tool I linked to is developed by Microsoft itself, so that’s how I troubleshot my own issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript doesn't fire on some computers - MSDN - Microsoft
If it's the same browser on different computers, then the script has to work the same. It has to. What exactly is not...
Read more >
Batch script the same on both PC's but not working?
A simple echo %thisvariabledoesnoexist:"=% will show the same result. The reason for the observed output is that the variable %user% ...
Read more >
My script only works sometimes on different computers - AutoIt
Hey guys i have used kodos tool to make an simple gui and put some files into the root where i got my...
Read more >
Script runs on one Windows 10 computer and not on another.
Many times I find out the reason why a script doesn't run the same on two different computers is because the permissions are...
Read more >
UAC prevents backup script from running but only on SOME ...
I have a backup script that runs every night on all the computers on our network. It works fine on 7... | Windows...
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