creotiv / MiBand2

Library to work with Xiaomi MiBand 2
Creative Commons Zero v1.0 Universal
544 stars 173 forks source link

Raw acceleration data and raw heart data missing #5

Open YibaiMeng opened 6 years ago

YibaiMeng commented 6 years ago

When running example.py, there appears to be no Raw accel and Raw heart data. Perhaps the band firmware changed its instruction, or perhaps the band removed the functionality altogether.

My firmware data is as follows:

Soft revision: V1.0.1.81
Hardware revision: V0.9.3.4
bailubme commented 6 years ago

Hi @creotiv

I had the same problem with the post above. Could you please share some insights on it? Thanks.

JosePProenca commented 6 years ago

Hi, I’m not being able to receive the accelerometer data. I‘m calling the start_raw_data_realtime function, but it never prints a request for accelerometer data. I think this is because the code, as it is on the GitHub, only sends the requests for HR data, am I correct? What should I write into the char_ctrl to receive the desired data?

Thank you

creotiv commented 6 years ago

@JosePProenca Example.py should give all raw data HR & accel data.

It's strange cause i have same hardware and software version on my band. Did it pair device without problems?

JosePProenca commented 6 years ago

Yes, it paired without any issues, but only prints heart rate measurements.

creotiv commented 6 years ago

Then i don't know whats happening there, try to run wireshark and trace all BT packets.

JosePProenca commented 6 years ago

Alright, thanks :)

DavidM42 commented 6 years ago

So how did it turn out? Were you able to solve the issue because I'm facing the same problem.

Wingjam commented 5 years ago

I'm also facing the same problem, any updates?

franalotto94 commented 5 years ago

Hello Everyone,

I really need raw data from motion sensors. I've tried with the following code: char_sensor.write(b'\x01\x03\x19') char_sensor.write(b'\x02')

But nothing is notified by the device.

I've also tried to trigger only motion raw data (no hearth rate raw data) by sending char_sensor.write(b'\x01\x01\x19') char_sensor.write(b'\x02')

Both bytes have been sent to CHARACTERISTIC_SENSOR. Now I'm expecting that some notifies should be triggered by CHARACTERISTIC_HZ but nothing happens.

Please help me to manage this problem.

I've checked UUID and they are the same.

Someone has solved? can please share a possible solution to it ?

Thank you in advance

Paulolrl commented 4 years ago

@franalotto94 I'm facing the same issue, were you able to find a solution?

fral8 commented 4 years ago

@franalotto94 I'm facing the same issue, were you able to find a solution?

Hello @Paulolrl , Unfortunately, I was unabe to find a right solution to this issue. I suppose a changement in the following hardware revisions of the miband for the BT unit....

Jhilam2014 commented 4 years ago

I am facing the same issue. I have triggered motion raw data as well. char_sensor.write(b'\x01\x01\x19') char_sensor.write(b'\x02')

it is returning False for char_sensor.supportsRead()

also when I am trying to read the data from char_sensor char_sensor.read() raise BTLEGattError("Bluetooth command failed", resp) BTLEGattError: Bluetooth command failed (code: 2, error: Attribute can't be read)

Any solution???

luthis1124 commented 4 years ago

Has anyone made any progress getting the raw accel data yet?

Paulolrl commented 4 years ago

Hi, sorry for not reporting it earlier, but I was able to make at least the raw acceleration works. Here is my code:

def start_raw_data_realtime(self, heart_measure_callback=None, heart_raw_callback=None, accel_raw_callback=None):

        char_sensor1 = self.svc_1.getCharacteristics(UUIDS.CHARACTERISTIC_HZ)[0]
        char_sens_d1 = char_sensor1.getDescriptors(forUUID=UUIDS.NOTIFICATION_DESCRIPTOR)[0]

        char_m = self.svc_heart.getCharacteristics(UUIDS.CHARACTERISTIC_HEART_RATE_MEASURE)[0]
        char_d = char_m.getDescriptors(forUUID=UUIDS.NOTIFICATION_DESCRIPTOR)[0]
        char_ctrl = self.svc_heart.getCharacteristics(UUIDS.CHARACTERISTIC_HEART_RATE_CONTROL)[0]

        if heart_measure_callback:
            self.heart_measure_callback = heart_measure_callback
        if heart_raw_callback:
            self.heart_raw_callback = heart_raw_callback
        if accel_raw_callback:
            self.accel_raw_callback = accel_raw_callback

        char_sensor = self.svc_1.getCharacteristics(UUIDS.CHARACTERISTIC_SENSOR)[0]

        char_ctrl.write(b'\x15\x02\x00', True)
        char_ctrl.write(b'\x15\x01\x00', True)
        char_sens_d1.write(b'\x01\x00', True)
        char_sensor.write(b'\x01\x03\x19')
        char_d.write(b'\x01\x00', True)
        char_ctrl.write(b'\x15\x01\x01', True)
        char_sensor.write(b'\x02')

        t = time.time()
        while True:
            self.waitForNotifications(0.5)
            self._parse_queue()
            # send ping request every 12 sec
            if (time.time() - t) >= 12:
                char_sensor.write(b'\x01\x03\x19')
                char_sensor.write(b'\x02')
                char_ctrl.write(b'\x16', True)
                t = time.time()
luthis1124 commented 4 years ago

Works perfectly! I just replaced the method and copied this in.

Waved around the Mi Band and can see data updating.

Raw accel heart: [{'x': 1, 'y': -7, 'wtf': 125}, {'x': 13, 'y': -11, 'wtf': 127}, {'x': 5, 'y': -18, 'wtf': 124}] Raw accel heart: [{'x': 3, 'y': -4, 'wtf': 127}, {'x': 5, 'y': -7, 'wtf': 130}, {'x': 6, 'y': 7, 'wtf': 133}] Raw accel heart: [{'x': -5, 'y': -64, 'wtf': 101}, {'x': 20, 'y': -8, 'wtf': 126}, {'x': 21, 'y': 33, 'wtf': 108}] Raw accel heart: [{'x': 6, 'y': -2, 'wtf': 132}, {'x': 9, 'y': 2, 'wtf': 127}, {'x': 11, 'y': 2, 'wtf': 125}] Raw accel heart: [{'x': 10, 'y': 2, 'wtf': 128}, {'x': 8, 'y': 2, 'wtf': 124}, {'x': 10, 'y': 1, 'wtf': 127}]

DavidM42 commented 4 years ago

I tried your code @Paulolrl and it works great. Only problem is I'm not getting achieving a high rate of movement detection right now. Did I understand the returned data correctly? It returns an array with 3 items, every item is a pair of x,y,wtf values so I assumed that every item is an item in sequence. Am I right that I can compare the values from the returned three items to detect changes in movement/direction? But then I only get new value arrays every ~500ms to ~600ms

luthis1124 commented 4 years ago

I made the below change

        def _parse_raw_accel(self, bytes):
        res = []
        # range() changed from 3 to a 1:
        for i in range(1):

and added:

# uncomment the below line to fix!
            # res.append({'x': g[0], 'y': g[1], 'wtf': g[2]})
            if g[0] > 150:
                print("++++++++++++++++++++++XXXXXXXXXXXXXXXXXXXXXXXXX")
            if g[0] < -150:
                print("---------------XXXXXXXXXXXXXXXXXXXXX")
            if g[1] > 150:
                print("+++++++++++++++++++++++YYYYYYYYYYYYYYYYYYYYYYY")
            if g[1] < -150:
                print("---------------YYYYYYYYYYYYYYYYYYY")

just to get single lines, so I could tell what axis is what, and how predictably I could move the band. Seems a bit unpredictable, I'm not expecting the band to be that accurate anyway. not sure on the 'for i in range(3):'