Skip to content

Instantly share code, notes, and snippets.

@HDR
Last active February 15, 2025 04:31
Show Gist options
  • Save HDR/4a778f21a05dbb9648d26e15acd3eb0c to your computer and use it in GitHub Desktop.
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
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