Last active
February 15, 2025 04:31
-
-
Save HDR/4a778f21a05dbb9648d26e15acd3eb0c to your computer and use it in GitHub Desktop.
Connect to a Huawei smart watch in Huawei HR Data Broadcast mode and display the heartrate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from bleak import BleakScanner, BleakClient | |
huawei_device = None | |
huawei_heartrate_char_uuid = "00002a37-0000-1000-8000-00805f9b34fb" | |
async def notification_handler(sender, data): | |
heart_rate = data[1] | |
print(f"Heart Rate:{heart_rate} BPM", end="\r") | |
async def connect(): | |
print("Scanning for a Huawei device in HR Data Broadcast mode") | |
devices = await BleakScanner.discover() | |
global huawei_device | |
for device in devices: | |
if "HUAWEI" in (device.name or ""): | |
huawei_device = device.address | |
if huawei_device: | |
print(f"Found Huawei device address: {huawei_device}") | |
async with BleakClient(device) as client: | |
await client.start_notify(huawei_heartrate_char_uuid, notification_handler) | |
while True: | |
await asyncio.sleep(1) | |
else: | |
print("No Huawei device in HR Data Broadcast mode found") | |
return | |
devices = asyncio.run(connect()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment