This repository was archived by the owner on Feb 7, 2023. It is now read-only.
forked from yogeshojha/MiBand3
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (62 loc) · 2.05 KB
/
main.py
File metadata and controls
70 lines (62 loc) · 2.05 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
from auth import MiBand3
from constants import ALERT_TYPES
import time
import os
# Set MAC address of your band here
MAC_ADDR = "00:00:00:00:00"
# need to initialize or not
INIT = False
# create object
band = MiBand3(MAC_ADDR, debug=False)
band.setSecurityLevel(level = "medium")
# Authenticate the MiBand
if(INIT):
if band.initialize():
print("Initialized...")
band.disconnect()
sys.exit(0)
else:
band.authenticate()
def get_band_details():
# put everything into pretty dictionary
band_data = {
"Soft revision":band.get_revision(),
"Hardware revision":band.get_hrdw_revision(),
"Serial":band.get_serial(),
"Battery":band.get_battery_info(),
"Time":band.get_current_time(),
"Steps":band.get_steps()
}
return band_data
def accel_raw_callback(accel_raw):
print("Accelerometer raw data: %s" % accel_raw)
def heart_beat_raw_callback(heart_raw):
print("Heartbeat raw data: %s" % heart_raw)
def heart_beat_callback(beat):
print("Heartbeat BPM: %s" % beat)
def main():
# sending call alert demo
band.send_alert(ALERT_TYPES.PHONE)
# sending message alert demo
band.send_alert(ALERT_TYPES.MESSAGE)
# sending custom message demo
band.send_custom_alert(5,"Hello World")
# sending custom call demo
band.send_custom_alert(3,"Xiaomi calling")
# sending custom missed call message
band.send_custom_alert(4,"Missed call from Xiaomi")
# change the watch to custom time and date
band.change_date("dd-mm-yyyy HH:MM:SS")
# get heart beat continuesly
band.start_raw_data_realtime(heart_measure_callback=heart_beat_callback)
# get raw heart monnitor data
band.start_raw_data_realtime(heart_raw_callback=heart_beat_raw_callback)
# get accelerometer raw data
band.start_raw_data_realtime(accel_raw_callback=accel_raw_callback)
# stop all realtime activity from the band
band.stop_realtime()
# update the band firmware
band.dfuUpdate("/full/firmware/location/goes/here/firmware.fw")
if __name__ == "__main__":
main()