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.

Problem with start_notify, bleak

See original GitHub issue
  • bleak version: 0.14.3
  • Python version: 3.9.12
  • Operating System: macOS 10.15.7

Hi! I have to read the weight from a Mi Smart Scale 2 scale via Mac.

The weight is encoded in a BLE characteristic. However, sometimes it reads the weight, other times it doesn’t.

I’m using the code found in the Bleak repository examples and this is my code:

import sys
import asyncio
import platform

from bleak import BleakClient

CHARACTERISTIC_UUID = "00002a9d-0000-1000-8000-00805f9b34fb"
ADDRESS = (
    "70:87:9e:0f:f8:7d"
    if platform.system() != "Darwin"
    else "775A199B-A238-4AB7-86EB-4EFF8C404F9A"
)


def notification_handler(sender, data):
    """Simple notification handler which prints the data received."""
    data1 = list(data)
    data2 = ((data1[1]+data1[2]*256)*0.005)
    print("{0}: {1}".format(sender, data2))


async def main(address, char_uuid):
    async with BleakClient(address) as client:
        print(f"Connected: {client.is_connected}")

       
        await client.start_notify(char_uuid, notification_handler)
        await asyncio.sleep(30.0)
        await client.stop_notify(char_uuid)
        


if __name__ == "__main__":
    asyncio.run(
        main(
            sys.argv[1] if len(sys.argv) > 1 else ADDRESS,
            sys.argv[2] if len(sys.argv) > 2 else CHARACTERISTIC_UUID,
        )
    )

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
dlechcommented, Jun 8, 2022

tried to install Xcode to acquire bluetooth packets but I don’t have enough memory space

You don’t need to install XCode, just the hardware utilities from the apple developer website

I think the problem is related to caches or in general to the saving session… What do you think about it?

If the device is listed in the Bluetooth system settings, try removing it there.

1reaction
dlechcommented, Jun 8, 2022

Have you tried the troubleshooting recommendations in the Bleak docs (enable logging, capturing Bluetooth packets)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Bleak start_notify callback not invoked - Stack Overflow
I tried to connect my ble device using Python bleak module. The device is getting scanned and connected. I try to enable notification...
Read more >
Troubleshooting — bleak 0.20.0a1 documentation
If you're having difficulty connecting to multiple devices, try to do a scan first and pass the returned BLEDevice objects to BleakClient calls....
Read more >
How to use the bleak.BleakClient function in bleak - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
bleak · PyPI
Bleak is an acronym for Bluetooth Low Energy platform Agnostic Klient. Free software: MIT license ... It will cause a circular import error....
Read more >
Python Tutorial 1: Connect BLE : Open GoPro - GitHub Pages
... a walk-through to connect to the GoPro camera via BLE using bleak. ... add this feature and progress can be tracked on...
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