BeMacized / xiaomi_scale

A Flutter plugin for taking measurements from Bluetooth Xiaomi weight scales
https://pub.dev/packages/xiaomi_scale/
MIT License
18 stars 9 forks source link

Xiaomi Mi Scale 2 get all properties #7

Closed vanlooverenkoen closed 2 years ago

vanlooverenkoen commented 4 years ago

For now this package only supports getting your weight

This is also supported by the scale. Is there a way to get these values as well?

https://dev.to/henrylim96/reading-xiaomi-mi-scale-data-with-web-bluetooth-scanning-api-1mb9

https://github.com/wiecosystem/Bluetooth/blob/master/sandbox/huami.health.scale2/body_metrics.py

BeMacized commented 4 years ago

I figured the conversion to get these values from the impedance value would have been some black box algorithm on Xiaomi's part, so I never really considered looking into it. If that algorithm in the 2nd link works for this scale as well, that does make things a lot easier.

Currently I'm not interested in implementing this due to time constraints, but I'll gladly merge a PR.

I have a hunch that the impedance value might be stored in bytes 9 and 10 of the advertisement data.

vanlooverenkoen commented 4 years ago

Because we only need 1 number for the calculation: BIA (Bioelectrical impedance analysis) https://en.wikipedia.org/wiki/Bioelectrical_impedance_analysis

https://github.com/oliexdev/openScale/blob/390fc410536a05f8308a49d23b397b6ba56f6129/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/MiScaleLib.java#L23

I am trying to use this java class for parsing the extra fields

The only thing we apparently need is the impedance which is stored in here:

impedance = ((data[10] & 0xFF) << 8) | (data[9] & 0xFF);

This is what it looks like:

Screenshot_20200818-203708.png

vanlooverenkoen commented 4 years ago

I compared the results with the results from the xiaomi app.

And this is exactly the same. So I think we can use this to get the extra data

hmmunioz commented 2 years ago

I need help the impedance value is always null and I can't get the other data can someone help me @vanlooverenkoen

vanlooverenkoen commented 2 years ago

@hmmunioz what scale are you using?

I only have a Mi Body Composition Scale 2 so I only tested that scale

hmmunioz commented 2 years ago

@vanlooverenkoen hi bro, I use the same My body composition scale 2, can you please share the complete project with me, because I don't understand why the impedance is still null, I don't know if I have a problem with the code, could you please send it to me

vanlooverenkoen commented 2 years ago

The example is the complete project. So you should be able to use the example. And that should not give you a null value.

hmmunioz commented 2 years ago

hoooooolly s***t, it worked friend, I add an impedance != null before return MiScaleData in MI_scale_device_v2.dart, and and modified proccesData for the same condition, waaaaaaaaaaa I'm very happy it's working, thanks genius @vanlooverenkoen . How complex is it to make a similar plugin for the miband6?