Mi band 1S heartbeat live monitoring
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
Let me know what tests you want me to do to assist you.
Does the code work with Mi Band 1S for the other features ?
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.
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!
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.
I will receive my 1S in a week or so. Hopefully I will be of help to reverse engineer this thing.
Got my 1S. I'll try to fiddle with it for a while
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
// Takes random HR data at night and when you get up to modify Sleep deep duration, etc.
// Its used in running mode, thats the interesting part (Battery less than 3 days ...)
//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
UUID: 2a39 is Heart Rate Control Point (read/write)
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?
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
I'm from mobile, so it may be that some directions aren't 100% correct, but should help you getting started!
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
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)
One thing I noticed is that you probably need to register for notifications on the HEART_RATE_MEASUREMENT characteristic (see MiBandSupport#enableNotifications(TransactionBuilder, boolean)).
I still don't know where the connection problems could stem from.
sure, im running under android emu (haxm 6.0) and in a tablet with 4.4, no other android phone devices to dev right now, waiting my Note2 until returns from vacations.
Edit: The problem here, couldnt pair any band, so couldnt test HR button .. i think that the last update with FW 126.96.36.199 for 1S and FW 188.8.131.52 for the 1 model broke the pair system, at least here. Anyone with theses versions could deny this?
Alright -- if you still have exceptions in your log, please post them here; maybe we should handle them differently than just logging + continue.
In android 6 its needed to search under BLE 👍
E BluetoothUtils: Permission denial: Need ACCESS_COARSE_LOCATION or
ACCESS_FINE_LOCATION permission to get scan results
PS. Ok going to give some extra info about those crash
as far as I understand it's needed for bt scan in background, which I don't think we are doing/need to do.
When i started my fork, just running current version gives this permission exception, im the only one using AE 2 with the new emu? its blazing
I'm not using Android studio 2 but I'll try it if you deem it worthwhile (especially since 1.5 gives me debugging issues).
As for the permission error I had no doubt that you added the permission because it was asked by the system, what I meant is that I'd very much prefer to remove the requirement for it (eg by doing the discovery in a different way) instead of adding it 😃
Ofc im agree with that idea, location its a dumb permission, dont look if could be another way to do it.
Regards and happy new year's eve
Tested with 3 bands, 1 and 1S infinite trying to pair without any sign in theses bands ( are free and unpaired and without miFit installed ).
PS. another error found comes when the own the device is searching, so the app could start the search.
01-02 13:27:55.228: I/nodomain.freeyourgadget.gadgetbridge.activities.DiscoveryActivity(17650): Starting BTLE Discovery
01-02 13:27:55.238: D/BluetoothAdapter(17650): startLeScan(): null
01-02 13:27:55.238: E/BluetoothAdapter(17650): LE Scan has already started
Just a note related to this.
I got MI1S last week and I cannot connect it to Gadgetbridge (GB) normally. I've tried with v 0.6.9 and with v0.7.0
The firmware of MI1S is "HW: 1S FW: 184.108.40.206"
I also have MI1A which has worked with GB.
When I go to GB/"Connect New Device", it always finds just MI1A and not MI1S. And I have checked "Mi Fit" is not running in background.
If I go to GB settings/"Mi Band Settings" and put in the correct "Mi Band address" of the MI1S, then now with v0.7.0 GB can find the band. The band is then recognized but named just as "MI", not "MI1S" as "MI1A" is.
When trying to synchronize, fails with: "Gadgetbridge: Data transfer failed"
I have "Write Log Files" enabled and GB is restarted but somehow there is no any "gadgetbridge" directory in /mnt/sdcard/Android/data/ so where does the log files go then?
There was a directory for gadgetbridge before, but I uninstalled app and re-installed, and now it does not have that directory in /mnt/sdcard/Android/data/ anymore.
I connected GB to MI1A, and then it created that /mnt/sdcard/Android/data/nodomain.freeyourgadget.gadgetbridge/ directory again, and /files/gadgetbridge.log is there.
So with MI1S GB is so incompatible it does not get to that stage it would create gadgetbridge.log file.
There is many Java NullPointerExecptions in the gadgetbridge.log file, which is attached.
In the log file, first I have connected to MI1A, but then later always just trying to connect to MI1S and if successful, then trying to synchronize. Synchronizing sometimes starts, but claims it gets more data what was asked.
@zimonish regarding the missing gadgetbridge directory -- did you re-enable the "Write Log Files" option after reinstlaling Gadgetbridge? The directory should be created right on startup (after enabling the option and restarting gadgetbridge) and it really is independent of the Mi Band model.
I do not remember if I needed to re-enable "Write Log Files" or was it already there after re-installing GB.
I also found it strange after removing GB installation and then re-installing it did not create that GB data directory in .../Android/... and even when trying to use GB with Mi1S it did not create it. Only after I connected to Mi1A it did create that directory. I can of course try to repeat the behaviour by removing and re-installing once again.
Preferences are also deleted when uninstalling.
Maybe your SD card was unmounted on startup so that Gadgetbridge simply could not create the directory? But if we want to debug this further, we need to open a separate ticket for this.
Any news about work with heart rate senser?
test from last night using 10minutes measures
accomplished first by someone else
I made some mistakes in my interpretation, sorry about that but only have an old tablet with Android :-/
Tried on phone running android 5.1 and tablet running 4.4.2
MI 1s FW 220.127.116.11 Gadgetbridge 0.7.4 Mi fit is not installed (and never was on tablet)
Band recognized. Test sms etc in debug works fine. Locate device etc fine.
Same errors on both when trying to sync data: error buffering activity data remaining bytes: 5 received: 20
No data populates in your activity. quit and reloaded a few times. Added non-default biometric data because of some of what's in the log. No change in errors. Also took me multiple quit lauch cycles before it would generate log.
Log has file has multiple attempts.
Recently I was able to get SportsTrackLive (STL) to support Mi1S with these instructions:
So the latest Mi Fit version supports continuing HR monitoring during an exercise. Having that ON, and starting SportsTrackLive, also STL was able to read HR monitoring and record an exercise.
I cherry-picked and @KashaMalaga's commits locally and enabled heart rate measurement for sleep mode. Let's see how it looks, tomorrow :-)
I can enable heart rate scanning, the green LEDs light up (at least once), but the rate we receive is always 0. FWIW, I get the same result with miband-sdk-android. Needs some more digging, I guess.
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.
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 ;(
Great, thanks a lot for testing! Then we can gradually make more interesting features available, than just the button in the Debug screen :-)
Thank you! Heart Rate Test works, I can confirm! FW: 18.104.22.168 ☺️
Heart rate test works for me as well! Would love to be able to put it in continuous mode and download that data.
@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.
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.
HW: 1S FW: 22.214.171.124 I'm not sure how to check HR firmware version.
Debug: Heart Rate test - works fine
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, I only used the one from newest Mi Fit. FW: 126.96.36.199
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 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: https://github.com/Freeyourgadget/Gadgetbridge/issues/249
Deleting a branch is permanent. It CANNOT be undone. Continue?