4lhc / MiBand_HRX

Library to work with Xiaomi MiBand HRX Accelerometer Data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MiBand-HRX

Library to work with Xiaomi MiBand HRX Edition Accelerometer Data. Intended for extraction of accelerometer data only, for experimentaions with ROS and gesture recognition. Check out the ROS interfacing example here.

I couldn't find a solution that worked with MiBand HRX edition. This repo is forked from creotiv/MiBand2 and modified to work with HRX bands.

The following commands were helpful in identification of services and characteristics specific to HRX bands. Xiaomi doesn't provide user descriptions for the services and characteristics, which makes it harder. There are plenty of reverse engineered solutions for MiBand2 & 3 which were extremely helpful.

List services

gatttool -b <MAC-ADDRESS> -t random --primary

List characteristics

gatttool -b <MAC-ADDRESS> -t random --characteristics

BLE

  • Authentication is same as MiBand2

  • Services & Characteristics of interest

    • SERVICE_MIBAND1 : "0000fee1-0000-1000-8000-00805f9b34fb"
      • CHARACTERISTIC_SENSOR_CONTROL : "00000001-0000-3512-2118-0009af100700"
      • CHARACTERISTIC_SENSOR_MEASURE : "00000002-0000-3512-2118-0009af100700"
  • To receive accelerometer notification

    • Write without response 0x010119 to service 0000fee1-0000-1000-8000-00805f9b34fb characeteristic 00000001-0000-3512-2118-0009af100700
    • Write without response 0x02 to service 0000fee1-0000-1000-8000-00805f9b34fb characeteristic 00000001-0000-3512-2118-0009af100700
    • Write 0x0100 to notification descriptor to enable notification

Processing Accelerometer Data

Parsing

Data received in packets of byte size 20, 14 or 8.

Sample: 0x0100 0500 8200 0b00 0400 8000 0b00 0300 8100 0b00

0100 0500 8200 0b00 0400 8000 0b00 0300 8100 0b00
- signed x signed y signed z signed x signed y signed z signed x signed y signed z

Calculating Roll and Pitch

In the absence of linear acceleration, the accelerometer output is a measurement of the rotated gravitational field vector and can be used to determine the accelerometer pitch and roll orientation angles.

Plot

Sources & References

  1. Base lib provided by Leo Soares
  2. Volodymyr Shymanskyy
  3. Freeyourgadget Team
  4. ragcsalo's Comment
  5. Xiaomi band protocol analyze
  6. Tilt Sensing Using 3-Axis Accelerometer
  7. creotiv donate link

Run

  1. Install dependencies
pip install -r requirements.txt
  1. Turn on your Bluetooth
  2. Unpair you MiBand from current mobile apps
  3. Find out you MiBand MAC address
sudo hcitool lescan
  1. Run this to auth device
python example.py --mac MAC_ADDRESS --init
  1. Run this to get live accel data from the device
python example.py --live --mac MAC_ADDRESS
python example.py --help
  1. If you having problems(BLE can glitch sometimes) try this and repeat from 4)
sudo hciconfig hci0 reset

About

Library to work with Xiaomi MiBand HRX Accelerometer Data


Languages

Language:Python 64.6%Language:Jupyter Notebook 35.4%