Giter Club home page Giter Club logo

miband4's Introduction

Requirements Commit License

MIBAND 4 - Python Library

Library to interact with Xiaomi MiBand4. Only works on linux. demo

Updates(3/1/2021)

  • Alarm functionality.

Updates(10/27/2020)

  • (New Feature) Custom watchface files(.bin) support.
  • Firmware restore/update fixes.

Contributors

MiBand 4 provides superset of services provided by MiBand 2/3. For the services that were similar for both devices, the bluetooth characteristics, UUIDs and request/response byte sequence were the same. Therefore, I utilized some of the informations already uncovered by Freeyourgadget team and made use of the code by Andrey Nikishaev for MiBand2. I reverse engineered snooped ACL packets to fill in the pieces of the puzzle.

AuthKey

MiBand 4 with updated firmware requires server based pairing. This means, that you absolutely must use MiFit app to make the initial pairing, retrieve the pairing key and then use this key to pair with this library. Only some of the features of this library work without AuthKey of the band. Read Server based pairing for further details.

There are several ways to obtain the key.

Obtaining unique Authkey

On rooted phone you may grab the key from MiFit database which means that you must:

  • install MiFit
  • create an account
  • pair the band/watch
  • Then, execute the following command in a root shell terminal:
sqlite3 /data/data/com.xiaomi.hm.health/databases/origin_db_[YOURDBNAMEHERE] "select AUTHKEY from DEVICE"

On a non rooted phone you may consider using https://www.freemyband.com/

NOTICE: Every time you hard reset the band/watch, the Bluetooth MAC Address will be changed and you must grab a new key! Also, anytime you unpair your band/watch from MiFit, the pairing key will be invalidated and you must make new pairing in MiFit app.

Features that work without authkey

  • Sending Calls
  • Sending alerts
  • Sending Missed call notifications
  • Retrieving device info
  • Sending music title and music state(Playing/Paused)
  • Recieve music control events (Play/Pause/Forward/Backward/Volume Up/Volume Down/Enter Music app/ Exit Music app) through callbacks

Features that needs authkey

  • Updating watchface of the band
  • Retrieving heart rate (Realtime and Single time)
  • Firmware update/restore (This feature has the potential to brick your Mi Band 4. Do it at your own risk)
  • Retrieving steps count, calories count and fat burnt
  • Setting date and time
  • Fetching fitness data within certain past intervals.

Setup and demo

  • Clone this repo to your local machine using https://github.com/satcar77/miband4.git
  1. Install the dependencies. Libglib2 is required for bluepy.

    sudo apt-get install libglib2.0-dev
    pip3 install -r requirements.txt
    
  2. (Optional) Find AuthKey for your device and put it to auth_key.txt file in the current directory with the script.

  3. Turn off your Bluetooth on your mobile device paired with MIBand 4

  4. Find out your MiBand4 MAC address using hcitool

    sudo hcitool lescan
    // if you are having trouble
    sudo hciconfig hci0 reset 
    
  5. Run the miband4_console

    python3 miband4_console.py -m MAC_ADDRESS 
    

Contributing

Step 1

  • Option 1

    • ๐Ÿด Fork this repo!
  • Option 2

    • ๐Ÿ‘ฏ Clone this repo to your local machine

Step 2

  • HACK AWAY! ๐Ÿ”จ๐Ÿ”จ๐Ÿ”จ

Step 3

  • ๐Ÿ”ƒ Create a new pull request

miband4's People

Contributors

d34d633f avatar justkowal avatar mikewent avatar satcar77 avatar shahart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.