-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheart.py
30 lines (20 loc) · 859 Bytes
/
heart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import asyncio
from bleak import BleakClient, BleakScanner
HEART_RATE_UUID = "00002a37-0000-1000-8000-00805f9b34fb"
async def main():
print("Scanning for Polar H7 device...")
devices = await BleakScanner.discover()
polar_device = next((d for d in devices if "Polar H7" in d.name), None)
if not polar_device:
print("Polar H7 device not found. Make sure it's turned on and nearby.")
return
print(f"Found Polar H7 device: {polar_device.name}")
async with BleakClient(polar_device.address) as client:
print("Connected. Streaming heart rate data...")
def callback(sender, data):
heart_rate = data[1]
print(f"Heart Rate: {heart_rate} bpm")
await client.start_notify(HEART_RATE_UUID, callback)
while True:
await asyncio.sleep(1)
asyncio.run(main())