forked from creotiv/MiBand2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.py
More file actions
28 lines (24 loc) · 620 Bytes
/
Copy pathdump.py
File metadata and controls
28 lines (24 loc) · 620 Bytes
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
import sys
import os
import time
from base import MiBand2
from bluepy.btle import BTLEException
MAC = sys.argv[1]
filepath = sys.argv[2]
if os.path.exists(sys.argv[2]):
os.remove(sys.argv[2])
fp = open(filepath, 'a')
fp.write('time, heartrate\n')
def log(rate):
data = "%s, %s\n" % (int(time.time()), rate)
fp.write(data)
print data
while True:
try:
band = MiBand2(MAC, debug=True)
band.setSecurityLevel(level="medium")
band.authenticate()
band.start_heart_rate_realtime(heart_measure_callback=log)
band.disconnect()
except BTLEException:
pass