Python class to communicate with Xiaomi Mi band 1A fitness tracker. Should works on Python 3.4 under Linux OS (Ubuntu and Raspian).
I mainly use :
- Bluetooth sniffing with Wireshark
- Gadgetbridge logs file, source code and community.
- bluepy as a Bluetooth Low Energy library
Thanks to all.
You have to install bluepy.
pip3 install bluepy
Download the main class file and add it to your project
Import the class
import mi_band_1a
Instanciate object with user informations
mb1a = MiBand1A(gender=2, age=25, height=175, weight=70, alias="jbegood", which_hand=0, keep_data=True)
Scan with a 5s timeout all good device close enought with a -80 dBm RSSI threshold
if mb1a.scan_and_connect(5.0, ["c8:0f:10:01:02:03", "c8:0f:10:04:05:06"], -80) == True:
# do the rest (get characteristics, subscribe notifications, read/write informations, authenticate, activity/sensor data...)
Get useful services and characteristics
mb1a.get_services_and_characteristics()
Subscribe to useful notifications
mb1a.subscribe_to_notifications()
Read some public informations
print(" + device_info : ", mb1a.read_device_info() )
print(" + date_time : ", mb1a.read_date_time() )
print(" + battery : ", mb1a.read_battery() )
print(" + realtime_steps : ", mb1a.read_realtime_steps() )
Vibrate during 0.5s
mb1a.vibrate(0.5)
Flash leds"
mb1a.flash_leds()
Authenticate in order to read private informations (activity data and sensor data)
print(" + authenticate success : ", mb1a.authenticate() )
Fetch activity data, decode it to read the steps recorded inside
print(" + activity data steps recorded : ", mb1a.fetch_activity_data("dump_activity_data.csv") )
Read and record about 300 sensor data samples in a CSV file (a little bit more actually)
mb1a.record_sensor_data("dump_sensor_data.csv", 300)
Finally disconnect to the device
mb1a.disconnect()
Basic informations roadmap :
- read basic informations
batteryrealtime steps- date time
- device informations
- device name
- goal
- write basic informations
- date time
- device name
- goal
vibrate the wristlight on/off leds
Security informations roadmap :
handle pairing (for now you have to pair the device manually before using this class using bluetooth manager)authenticate to access private data (activity data and sensor data)
Sensor data roadmap :
read sensor data (accelerometer raw value)analyse and record sensor data (accelerometer raw value) in a CSV file
Activity data roadmap :
read activity data (steps, sleep) recorded in the deviceanalyse and count steps contained in activity data- analyse sleep informations contained in activity data
analyse and record sensor data (accelerometer raw value) in a CSV file
Other roadmap
- create a pip package
- write documentation
Release 0.1.0
- first release
- read basic informations like battery, realtime steps
- can read and record in a CSV file raw value from accelerometer
- can read and count steps done in activity data recorded in the device