-
Notifications
You must be signed in to change notification settings - Fork 0
/
ww.py
43 lines (31 loc) · 1.16 KB
/
ww.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
31
32
33
34
35
36
37
38
39
40
41
42
from btle import Peripheral, ADDR_TYPE_RANDOM, AssignedNumbers
import time
class HRM(Peripheral):
def __init__(self, addr):
Peripheral.__init__(self, addr, addrType=ADDR_TYPE_RANDOM)
if __name__=="__main__":
cccid = AssignedNumbers.client_characteristic_configuration
hrmid = AssignedNumbers.heart_rate
hrmmid = AssignedNumbers.heart_rate_measurement
hrm = None
try:
hrm = HRM('cb:d7:a0:40:c4:01')
service, = [s for s in hrm.getServices() if s.uuid==hrmid]
ccc, = service.getCharacteristics(forUUID=str(hrmmid))
if 0: # This doesn't work
ccc.write('\1\0')
else:
desc = hrm.getDescriptors(service.hndStart,
service.hndEnd)
d, = [d for d in desc if d.uuid==cccid]
hrm.writeCharacteristic(d.handle, '\1\0')
t0=time.time()
def print_hr(cHandle, data):
bpm = ord(data[1])
print bpm,"%.2f"%(time.time()-t0)
hrm.delegate.handleNotification = print_hr
for x in range(10):
hrm.waitForNotifications(3.)
finally:
if hrm:
hrm.disconnect()