danielsousaoliveira / miband-HR-python

Heart rate monitor for Mi Band 6 and Mi Band 7, in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heart rate monitor for Mi Band 6 and 7

This is a Python implementation of the miband-6-heart-rate-monitor

Real time heart rate monitor for Mi Band 6 and 7 using Python

Note: Currently Mi Band 7 is not working properly

Demonstration

Requirements

  1. Install dependencies:
sudo apt-get install libglib2.0-dev
pip3 install -r requirements.txt
  1. Clone tiny-ECDH-python
  2. Copy ecdh.python and utils.py files from the tiny ECDH to this repository
  3. Find gatt_linux.py on your computer (Should be on /home/user/.local/lib/python3.8/site-packages/gatt)
  4. Make the following changes on the file gatt_linux.py:
Class DeviceManager:

    # Add the following function to the Class
    def notification_query(self, function, device):
        GObject.timeout_add(10000, function, device)

Class Device:

    # Change the following function 
    def _connect(self):
        self._connect_retry_attempt += 1
        try:
            self._object.Connect()
            # Only this line is changed, remove the rest. Some bug doesn't allow to connect with Band 7
            if not self.services:
                self.services_resolved()

How to use

  1. Clone this repository
  2. Find your Mi Band's Authentication Key (Check Here)
  3. Put your authentication key to auth_key.txt file in the current directory.
  4. Turn off Bluetooth on your mobile device paired with the band
  5. Find out your band MAC address using bluetoothctl
sudo bluetoothctl
scan on
devices
  1. Run main script
# Mi Band 6
python3 main.py -m MAC_ADDRESS -b 6

# Mi Band 7
python3 main.py -m MAC_ADDRESS -b 6

References

Libraries

TODO

  1. Add continuous heart rate measurement to Mi Band 7 class
  2. Add alarm functionality to Mi Band 7 Class
  3. Implement spo2 measurement

About

Heart rate monitor for Mi Band 6 and Mi Band 7, in Python

License:MIT License


Languages

Language:Python 100.0%