-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitthr.py
50 lines (34 loc) · 1.42 KB
/
kitthr.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
43
44
45
46
47
48
49
50
from btle import Peripheral, ADDR_TYPE_PUBLIC, AssignedNumbers
import time
class HRM(Peripheral):
def __init__(self, addr):
Peripheral.__init__(self, addr, addrType=ADDR_TYPE_PUBLIC)
if __name__=="__main__":
cccid = AssignedNumbers.client_characteristic_configuration
hrmid = AssignedNumbers.heart_rate
hrmmid = AssignedNumbers.heart_rate_measurement
hrm = None
while True:
try:
hrm = HRM('F4:B8:5E:EB:C2:BA')
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')
def print_hr(cHandle, data):
bpm = ord(data[1])
output = open('/mnt/usb/kittlogs/hr.txt','w')
print >> output, bpm, int(time.time())
output.close()
print bpm
hrm.delegate.handleNotification = print_hr
hrm.waitForNotifications(1.)
if hrm:
hrm.disconnect()
except KeyboardInterrupt:
hrm.disconnect()