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:
- Created a year ago
- Comments:6
Top 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 >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
You don’t need to install XCode, just the hardware utilities from the apple developer website
If the device is listed in the Bluetooth system settings, try removing it there.
Have you tried the troubleshooting recommendations in the Bleak docs (enable logging, capturing Bluetooth packets)?