Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mi band 1S heartbeat live monitoring #178

Closed
boogerlad opened this issue Nov 29, 2015 · 72 comments

Comments

Projects
None yet
@boogerlad
Copy link

commented Nov 29, 2015

This feature isn't implemented yet. In the mi fit app, I took a bluetooth trace of it while it was measuring my heart beat.

6274 736e 6f6f 7000 0000 0001 0000 03ea
0000 000f 0000 000f 0000 0000 0000 0000
00e2 0365 dc2c 57e4 0240 000a 0006 0004
0012 4e00 1502 0100 0000 0800 0000 0800
0000 0300 0000 0000 e203 65dc 3034 7c04
1305 0140 0001 0000 0000 0a00 0000 0a00
0000 0100 0000 0000 e203 65dc 4004 ee02
4020 0500 0100 0400 1300 0000 0e00 0000
0e00 0000 0100 0000 0000 e203 65dc c4f0
ff02 4020 0900 0500 0400 1b4b 0006 46
@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Nov 30, 2015

Thanks! I didn't check yet, but I hope the Mi Band uses the standard bluetooth LE heart rate profile (http://developer.bluetooth.org/TechnologyOverview/Documents/HRP_SPEC.pdf).

@boogerlad

This comment has been minimized.

Copy link
Author

commented Nov 30, 2015

Let me know what tests you want me to do to assist you.

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Nov 30, 2015

Will do. Might take a little while, though.

@omairaslam

This comment has been minimized.

Copy link

commented Dec 4, 2015

Does the code work with Mi Band 1S for the other features ?

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2015

@omairaslam
We do not know, since no one of us own a Mi Band 1S (yet?)

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2015

Anybody out there who owns a model 1S? Please test with Gadgetbridge and report any issues!

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2015

Related: #162

@bymodude

This comment has been minimized.

Copy link

commented Dec 8, 2015

Im trying to connect MI1S in Gadgetbridge it says connecting, initialized, connected and then "not connected" again, so basically cant connect

attached is a logcat output
1slogcat.txt

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 8, 2015

Thanks for the log, will have a look later in the evening.

cpfeiffer added a commit that referenced this issue Dec 8, 2015

User Info is probably the same for MI 1A and 1S #178
Can you please test whether this fixes the connection problems?
@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 8, 2015

FWIW, 0.6.9 is released with the above fix.I hope/think this will fix your connection problems. I'm afraid that notifications upon received sms, chat messages, etc. will not work, though (you can try them in the Debug screen).

It looks like the notification API has changed again in current Mi Band firmwares and we have to adjust to that. Notifications might still work with the firmware from Mi Fit 1.5.912-1539.

@bymodude

This comment has been minimized.

Copy link

commented Dec 9, 2015

thanks for the prompt fix! however I tried it with 0.6.9 and still having the same problems, logcat attached
1s_logcat_069.txt

@bymodude

This comment has been minimized.

Copy link

commented Dec 10, 2015

Thanks, this commit indeed makes it work, the MI1S successfully connects and shows battery percentage, however after 10 or 15 seconds it always disconnects, is this expected?
When I go to Debug / "send as SMS" the 1S is vibrating 3 times so that seems to work

I am mostly interested into accessing the heart rate sensor as well, would be great if that can be added to gadgetbridge!

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2015

No, this is not expected. It might be due to a bad bluetooth stack on the mobile, bad firmware on the Mi Band or due to us doing something (or not doing something).

Could you attach another log including the disconnect? BTW, there is also a log option in Gadgetbridge's preferences, which will save the log to a file. It will only contain Gadgetbridge's log statements, though.

Regarding the heart rate sensor: could you try to find out whether the Mi Band supports the standardized bluetooth heart rate profile? Google's BLE Sample app ( https://github.com/googlesamples/android-BluetoothLeGatt) or the modified version (https://github.com/movisens/android-SmartGattLib-Example) should provide this information for example.

If the standard profile is used, we could add support for it without actually having a device to test against.

@tapir

This comment has been minimized.

Copy link

commented Dec 15, 2015

I will receive my 1S in a week or so. Hopefully I will be of help to reverse engineer this thing.

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 16, 2015

Cool, looking forward to that :-)

@KashaMalaga

This comment has been minimized.

Copy link
Contributor

commented Dec 21, 2015

Hello, Im here to help, i´ve got the 1S and checking how its working ;)
logINFO1S.txt

@tapir

This comment has been minimized.

Copy link

commented Dec 26, 2015

Got my 1S. I'll try to fiddle with it for a while

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 27, 2015

Great, let us know how it works out!

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 27, 2015

@KashaMalaga Would you like to clone our repo so that we can work together on supporting the heartrate sensor?

@KashaMalaga

This comment has been minimized.

Copy link
Contributor

commented Dec 28, 2015

Ofc i could help over here!!
Going to clone and start digging into your project 👍

Obviously Xiaomi doesnt share the complete BLE stack for HR measuring so isnt working with all those common apps to measure HR.

I´ve found 3 diferent modes to read:
UUID: 2a39 to read
UUID: 2a37 onNotify/SR
parameters:
SLEEP((byte) 0),
// Takes random HR data at night and when you get up to modify Sleep deep duration, etc.
CONTINUOUS((byte) 1),
// Its used in running mode, thats the interesting part (Battery less than 3 days ...)
MANUAL((byte) 2);
//This one is the known mode from the Xiaomi app, dont like it cause with just a few reads ..if you are moving or in a bad position, +160bpm ...

That's a resume about my short search

@rs9000

This comment has been minimized.

Copy link

commented Dec 30, 2015

UUID: 2a39 is Heart Rate Control Point (read/write)
and
UUID: 2a37 is Heart Rate Measurement (notify only)
So data are stored in 2a37 but this address is inaccessible and gattlib return me this error
"Read characteristics by UUID failed: Attribute can't be read".
How can I turn on sensor and read bpm?

@danielegobbetti

This comment has been minimized.

Copy link
Contributor

commented Dec 30, 2015

you can try like this:
-register the notification on the notify endpoint (see in mibandsupport for other characteristics where we do the same), then you need to modify oncharacteristicchanged to deal with the notifications on this characteristic, you can use logmessagecontent as handler at the beginning (it just logs to logcat)
-activate the hr readings by writing to the hr control characteristic
-profit? :)

I'm from mobile, so it may be that some directions aren't 100% correct, but should help you getting started!

@rs9000

This comment has been minimized.

Copy link

commented Dec 30, 2015

I would activate hr readings, but what should I write in what address?
I understand that:
handle: 0x0049, uuid: 2800 value: 0d18 (HR service)
handle: 0x004a, uuid: 2803 value: 10 (options) 4b00 (hnd) 372a (uuid)
handle: 0x004b, uuid: 2a37 (HR Measuremnet) value: unaccessible
handle: 0x004c, uuid: 2902 value: blank
handle: 0x004d, uuid: 2803 value: 0a (options) 4e00 (hnd) 392a (uuid)
handle: 0x004e, uuid: 2a39 (HR Control point) value: 00 00

So I tried to write in uuid 2803 the value 0a4b00372a but it is read-only

@KashaMalaga

This comment has been minimized.

Copy link
Contributor

commented Dec 31, 2015

Dont have a real Android device to test, just trying under vm+ble and emu :(
Could someone check my version in my repo?? Since Dec 28
Couldnt sync any band, 1,1A or 1S always trying to connect and no messages (or vmware just keep on trolling me)

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Dec 31, 2015

@KashaMalaga Great work! At a first glance, your commits look perfect, there's no reason why connecting shouldn't work anymore. I'll have a closer look to check if I missed something.

cpfeiffer added a commit that referenced this issue Feb 27, 2016

cpfeiffer added a commit that referenced this issue Feb 27, 2016

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2016

I just pushed the changes so that you guys can try it, too. The Debug screen has a new button "HR Rate Test", which you can press. Then you should get some log output, in logcat and the logfile about the heart rate measurement results.

cpfeiffer added a commit that referenced this issue Feb 27, 2016

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2016

I just pushed another change. Please use the Debug activity and press the "Heart Rate Test" button. This will cause a "manual" heart rate measurement, which takes about 4-5 seconds. The result will be displayed as a short popup (toast).

Please test this if you can and report back if you get any meaningful value.

I only get 0 as value ;(

cpfeiffer added a commit that referenced this issue Feb 29, 2016

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Feb 29, 2016

@Samarium151 and everybody else: we will release 0.8.1 tomorrow, so you can test whether heart rate reading works.

@danielfh

This comment has been minimized.

Copy link

commented Mar 2, 2016

@cpfeiffer I can confirm you that heart rate reading is working! Thank you :-)

FW: 4.15.12.10
HR: 1.3.74.64

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2016

Great, thanks a lot for testing! Then we can gradually make more interesting features available, than just the button in the Debug screen :-)

@gume

This comment has been minimized.

Copy link

commented Mar 3, 2016

Thank you! Heart Rate Test works, I can confirm! FW: 4.15.11.20 ☺️

@ragesoss

This comment has been minimized.

Copy link

commented Mar 3, 2016

Heart rate test works for me as well! Would love to be able to put it in continuous mode and download that data.

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Mar 4, 2016

@ragesoss Yes, that's the plan!

We already get heart rate data together with activity data when the band is in such a mode, and there's already some (currently disabled) code, that displays a curve of it.

Just takes some more time and love. Of well, and it would help if my band would produce other hr values than 0.

@gume

This comment has been minimized.

Copy link

commented Mar 8, 2016

Recently I received a new band from China. The heart rate was 0. I updated the firmware (I think there was no firmware on it) and now it displays the heart rate (not 0). I hope it will help you as well.

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Mar 9, 2016

@gume Thanks for the encouragement, much appreciated :-) Will continue work on firmware update ASAP. Fingers crossed!

@wanderer

This comment has been minimized.

Copy link

commented Mar 10, 2016

@gume how did you update the firmware?

@bigretromike

This comment has been minimized.

Copy link

commented Mar 10, 2016

HW: 1S FW: 4.15.12.10 I'm not sure how to check HR firmware version.
Debug: Heart Rate test - works fine

@sachinnair92

This comment has been minimized.

Copy link

commented Mar 10, 2016

@bigretromike How did you manage to fetch the heart rate. Can you give any Instruction / code to do so.

@bigretromike

This comment has been minimized.

Copy link

commented Mar 10, 2016

sure @sachinnair92, Gadgetbridge, click on band to connect to it (but done eneter it) click tree dots on right ...
debug, and test heart rate . and got 72 ~ which is what mi fit showed before clean format ;-)

@sachinnair92

This comment has been minimized.

Copy link

commented Mar 10, 2016

@bigretromike Thanks for the reply... Did you flash the Mi 1S band with any firmware or you used the default one ?

@bigretromike

This comment has been minimized.

Copy link

commented Mar 10, 2016

@sachinnair92, I only used the one from newest Mi Fit. FW: 4.15.12.10
I stoped using mi fit 2 days ago. Testing this one after I saw that there is semi support for 1S ;-) which is experimental, but I probably switch to something with data sync to 3rd party sites to keep all data in one place ;-)

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2016

Hooray, after updating the hr firmware via #234, I finally have a heartbeat :-)
So there is progress!

@sachinnair92 At the moment there is just a simple "Heart rate test" button in the Debug activity.. Press the button, wait a bit and you will get a toast with the measured value.

@bigretromike

This comment has been minimized.

Copy link

commented Mar 11, 2016

@cpfeiffer glad to hear that! ;-) I thing most if not everything (i cannot test all of them because dont know how) buttons in Debug menu work for 1S ! 👍 which is good.
Only problem now for me is the initiation bug: #249

cpfeiffer added a commit that referenced this issue Apr 12, 2016

cpfeiffer added a commit that referenced this issue Apr 12, 2016

Disabling sleep measurement for continuous measurement is not necessary
Looks like they don't interfere, after all. #178

cpfeiffer added a commit that referenced this issue Apr 13, 2016

@cpfeiffer cpfeiffer removed the help wanted label Aug 7, 2016

@cpfeiffer

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2016

I'm going to close this one, as live monitoring is already available. I'll open another issue to gather all sorts of improvements/new features related to heart rate measurements.

@cpfeiffer cpfeiffer closed this Aug 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.