Mi Band 3 pairing and fetching data (Heart Rate, Steps etc.) issue

1.1k Views Asked by At

Tried pairing Mi Band with GATT services and characteristics, no response from band. Issue same for both android and iOS. Only works with Mi Fit official app.

Neither updating nor notifying the updates for any of the characteristics except battery,Date, other info.

Note:- Tried services/characteristics -

  • FF0F
  • 2A37
  • 2A39
  • 0000180d-0000–1000–8000–00805f9b34fb
  • 0000fee0–0000–1000–8000–00805f9b34fb
  • 0000009–0000–1000–8000–00805f9b34fb
2

There are 2 best solutions below

0
On

I have noticed that in Mi Band 3 even without pairing(Authentication) you can access Heart Rate data and Details for heart rate measurement:

let BLE_Heart_Rate_Service_CBUUID = CBUUID(string: "0x180D")
let Heart_rate_UUID = CBUUID(string: "2A37")

Now put below code in didUpdateValueFor

if characteristic.uuid == Heart_rate_UUID {
            print("HeartRate_UUID reading: ", characteristic.value)
            peripheral.readValue(for: characteristic)
            print("HEART RATE:  ", getHeartRate(heartRateData: characteristic.value!))

        }

Use getHeartRate() for reading Heart Rate.

func getHeartRate(heartRateData:Data) -> Int{
        print("--- UPDATING Heart Rate..")
        var buffer = [UInt8](repeating: 0x00, count: heartRateData.count)
        heartRateData.copyBytes(to: &buffer, count: buffer.count)
        
        var bpm:UInt16?
        if (buffer.count >= 2){
            if (buffer[0] & 0x01 == 0){
                bpm = UInt16(buffer[1]);
            }else {
                bpm = UInt16(buffer[1]) << 8
                bpm =  bpm! | UInt16(buffer[2])
            }
        }
        
        if let actualBpm = bpm{
            return Int(actualBpm)
        }else {
            return Int(bpm!)
        }
    }
3
On

You will need to authenticate the app before start fetch data. The steps are:

  1. Enable notification for auth characteristics "0009"
  2. Send 18 bytes to the auth characteristics
  3. Once notified {0x10, 0x01, 0x01}, write another request that sends the first two bytes in (2)
  4. Once notified {0x10, 0x02, 0x01}, write another request that sends bytes with AES encrypted
  5. One notified {0x10, 0x03, 0x01}, you can proceed with other actions like fetching data.