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 4 Support #1536

Open
Progi1984 opened this issue Jun 12, 2019 · 91 comments

Comments

@Progi1984
Copy link

commented Jun 12, 2019

Before requesting a new feature, please confirm the following:

  • I have read the wiki, and I didn't find a solution to my problem / an answer to my question.
  • I have searched the issues, and I didn't find a solution to my problem / an answer to my question.

Your wearable device is:

  • Xiami Mi Band 4
@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

You have one?

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

What is the device (Bluetooth) Name?
Is there a firmware somewhere?

@R34V3N

This comment has been minimized.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

I pushed inittal "support", meaning the device might work as a Mi Band 3.

If you have such a device, please test master and report

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

I will tag a release very soon, please test if you can!

@ninfia

This comment has been minimized.

Copy link

commented Jun 19, 2019

First impressions of initial support:

  • Steps count doesn't sync at all. (Device set to 8000, Gadgetbridge still display 10000 steps)
  • Vibration and notification test doesn't work.
@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

@ninfia:

So pairing and connecting works?

Do phone calls work ?

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

@ninfia
Regarding "step count sync" - we do not sync. Gadgetbridge sends the configured step goal, we do not get it back from the device. If your device still has a goal of 8000, even when Gadgetbridge was set to 10000, then this feature also does not work.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

@ninfia
Honestly I have no idea what you tested, because connecting to the Mi Band4 probably did not work at all (that was just fixed in master) - OR - it was detected as a Mi Band 2 (if that was the case which unfortunately you cannot see), it is not fixed yet

What is the Bluetooth device name?

@R34V3N

This comment has been minimized.

Copy link

commented Jun 21, 2019

I can't pair my smartphone with miband 4. The application is blocked "connection in progress".

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 21, 2019

@R34V3N

Using self-compiled master?

And please finally someone....

tell me the Bluetooth device name! Is it Mi Smart Band 4?

@R34V3N

This comment has been minimized.

Copy link

commented Jun 22, 2019

The bluetooth device name is Mi Smart Band 4

@ninfia

This comment has been minimized.

Copy link

commented Jun 22, 2019

Self-compiled, it's identifed as MIBAND4 during attempt connection. (Or Mi Smart Band 4 in the device ID).

Paring doesn't work.

(Sorry for late response, had some trouble recovering email to log back to github)

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2019

@ninfia
Can you remove the if from:

and try again?

@ninfia

This comment has been minimized.

Copy link

commented Jun 22, 2019

Still failed to authenticate. I have tried both w/ and w/o Mi Fit.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2019

@ninfia

Thanks. Time to get a mi Band 4 i guess...
Or you could send me a Bluetooth hci dump while pairing with mi fit ;)

@ninfia

This comment has been minimized.

Copy link

commented Jun 22, 2019

Here's the btsnoop_hci.log

Will it helps?

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2019

@ninfia
Thanks, will analyze the file.
AS long as it contains the pairing it should be helpful :)

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 22, 2019

@ninfia
can you try the miband4_blind_experiments branch I just created and report back?
IF it should work to pair, please also try to disconnect and reconnect afterwards...

@ninfia

This comment has been minimized.

Copy link

commented Jun 23, 2019

Pairing works, but requires the device to be paired w/ Mi Fit. No auth screen for pairing.

(FW: 1.0.4.38, HW: V0.25.131.5)

Can't pair without mi fit (after unpaired from mi fit).

Reconnect works.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

@ninfia
Ok for clarification:

  1. did the miband4_blind_experiments change anything?
  2. the log you send was pairing in mi fit after having unpaired in mi fit?

I am not sure but in the past people reported they cannot connect/pair while mi fit was installed. I cannot confirm that because I never had mi fit on my phone.

@goldfndr

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

Codeberg-org pushed a commit that referenced this issue Jun 23, 2019

Codeberg-org pushed a commit that referenced this issue Jun 23, 2019

@ninfia

This comment has been minimized.

Copy link

commented Jun 24, 2019

@ashimokawa
1 - The miband4_blind_experiments indeed make it connected, however without any auth from the miband device. (there should be one, probably this is why it doesn't work without Mi Fit?).

However the notifications debug feature aren't working. (Vibrations happened, but band displayed as "No Notifications")

2 - Yes, the procedure is following. Unpaired -> Restart -> Enable HCI snooping -> Use Mi Fit to Pair -> Use Mi Fit to set a theme -> Use Mi Fit to Find Phone.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 24, 2019

@ninfia
Thanks, yes the paring sequence has changed significantly, and I missed something. Will push some more code soon (all untested of course).
What puzzles me is that the shared secret is not pushed to the band in the first step anymore. Normally it is like

  1. send shared secret
  2. request and receive random number
  3. encrypt that with the shared secret and send to band

here it is different - seemingly a random number comes in without step 1.

The log also contains other interesting stuff I didn't see before, and which seems to be unique to the mi band 4 (more flags are sent after connect).

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 24, 2019

@ninfia
If you have any other device like the mi band 3 I would also be interested in the bluetooth log for comparison.

@ninfia

This comment has been minimized.

Copy link

commented Jun 24, 2019

Unfortunately no, I didn't use a mi band for a while until the 4.

@cynnfx

This comment has been minimized.

Copy link

commented Jun 26, 2019

hello i can help you with that (i've got 3 and 4 mi band) just tell me wich test to do

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jun 26, 2019

@cynnfx
A bluetooth hci dump of the initial pairing (or pairing after unpairing) in mi fit of a mi band 3 would be interesting (to compare that to the mi band 4).
I fear a lot has changed...

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Jul 26, 2019

My point is just, that sniffing traffic is futile in my opinion. Prove me wrong and I am more than happy ;)

@saeugetier

This comment has been minimized.

Copy link

commented Jul 26, 2019

I just wanted to chime in I tried yesterday to...

check out and build the last master. we have managed to connect successful several Mi Band 4 devices with it. the only difficulty: you must bring your unique key. there are several ways, with and without rooted smartphone to obtain it. good luck!

Is there any documentation how to obtain the key?

@arizanovj

This comment has been minimized.

Copy link

commented Jul 27, 2019

I am interested in this as well. I am coding proof of concept app that utilizes WebBluetooth. I own MiBand4 and can help if you need something regarding logs/testing.

@Zvfhll

This comment has been minimized.

Copy link

commented Aug 3, 2019

Hello, can somebody please point me in the right direction on how to capture the authentication key. I have a rooted phone, but can't seem to find a guide or something on how to do it anywhere. Please help as I bought the band 4 specifically to use it with gadgetbridge

@vanous

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2019

@Zvfhll i do not have Mi Band 4 so i cannot help you any further, but i have added the description for getting the key on rooted phone to the wiki: https://github.com/Freeyourgadget/Gadgetbridge/wiki/Mi-Band-4#requirements

@minnux

This comment has been minimized.

Copy link

commented Aug 3, 2019

@tojaad mentioned there was a way to get the key without root. Do you have a link to that process as well?

@tojaad

This comment has been minimized.

Copy link

commented Aug 3, 2019

@tojaad mentioned there was a way to get the key without root.

Yeah. I found some possibilities to get the key on smartphones without root, but it is not quite legal, so sorry i don't want to post it here. Hint: look at some other 3th party apps. They will help you ;)

And on rooted devices this is very easy. Check the MiFit Database (origin_db).

@minnux

This comment has been minimized.

Copy link

commented Aug 4, 2019

@tojaad sorry but that doesn't help me at all. I have no idea what 3rd party app to look for and what exactly would be illegal about it.

@Nlsalz

This comment has been minimized.

Copy link

commented Aug 4, 2019

Hi, I used nrf connect and used the scanner. Is the key under Manufacturer data like this?

Manufacturer data (Bluetooth Core 4.1):
Company: Anhui Huami Information Technology Co., Ltd. <0x0157> 0x0090EEFCAAE2A55F5E....

Edit: I tried using this key (btw, keys change whenever I reconnect bluetooth with band) and waited for a couple of minutes for pairing. Did not connect though. Don't know why.

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2019

Xiaomi has locked down the pairing process, there is no other way then using mi fit and get the key with root (see wiki) or use a modified version of mi fit that tells you or a third party app the key.

Modification and redistribution of Mi Fit is illegal. Do not link such versions here.

If you do not have root you can install mi fit on a friends phone with your credentials and then that mi dit will sync the key from the cloud and you can get it there then uninstall.

@RichiH

This comment has been minimized.

Copy link

commented Aug 4, 2019

@tojaad

This comment has been minimized.

Copy link

commented Aug 4, 2019

If not, why would one need to enter one's own credentials?

The key is stored in Xiaomi's cloud...

@Nlsalz

This comment has been minimized.

Copy link

commented Aug 4, 2019

Xiaomi has locked down the pairing process, there is no other way then using mi fit and get the key with root (see wiki) or use a modified version of mi fit that tells you or a third party app the key.

Modification and redistribution of Mi Fit is illegal. Do not link such versions here.

If you do not have root you can install mi fit on a friends phone with your credentials and then that mi dit will sync the key from the cloud and you can get it there then uninstall.
Screenshot_20190804-194121__01 1

Is this the key that we need?

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2019

NO!

@Holzhaus

This comment has been minimized.

Copy link

commented Aug 6, 2019

If I understand correctly, the key is needed only for the pairing process. As far as I know, Mi Fit is using some kind of JSON API to talk to the servers. If we find out what the requests look like, it would be possible to let Gadgetbridge make them without needing the Mi Fit app.

Maybe people can enter their Mi Fit account credentials into Gadgetbridge, so that the app can request a pairing key for the device from the server. After pairing, Gadgetbridge would never contact the servers again, so the amount of data collected by Xiaomi would be neglible (just a throwaway email adress, a random password, the source IP the request was made from and the Mi Band's device ID).

@NotAFile

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2019

@Holzhaus I understand the gadgetbridge app deliberately does not have internet access permissions, so this needs a second app.

@Holzhaus

This comment has been minimized.

Copy link

commented Aug 8, 2019

This might be helpful:
https://gist.github.com/Holzhaus/4e469b57735e0faa2c66f71f110fadf6

Using a public key hash and the random bytes, the script requests a signature from Huami's servers.

@vanous

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2019

Interesting. The url In the script provided some interesting search results... For example https://github.com/huamitech/rest-api/wiki

@dj0001

This comment has been minimized.

Copy link

commented Aug 9, 2019

Perhaps this app can help to get the key (see The linked page)
r/miband
Untested, I have only miband3

@vanous

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2019

OK. Cool, so obviously, some solutions already exist. All of them will require either root, patched MiFit or API access.

  • The root method is already described in the wiki.
  • Patched MiFit app and distribution/linking to it is not something that belongs here, but creative people will be able to search for, if they prefer that.
  • API access requires network permission which GB is not to add, so again, creative people will be able to do with the Python gist. As Python installation might be hard, I can imagine that the simple Python code could be rewritten to completely client based JavaScript, but that and hosting is again, up to anyone.

I think the issue is solved and no further discussion is needed, in order not to pollute it here with further links to questionable content. We could rename this to 'MB4 pairing' and open a new generic MB4 issue for other unrelated things.

Of course, these are just my 2¢ 😃

@Holzhaus

This comment has been minimized.

Copy link

commented Aug 9, 2019

Well, the python script requires the pubkey hash and the random bytes sent from the device. Both are currently not displayed by Gadgetbridge. Also, I don't know how useful the script actually is, since the pairing might time out when the user has to enter or copy&paste the values around manually,

Ideally, we'd have a separate app with internet access that is used when we're pairing a Mi Band 4 and no auth key has entered manually (Similar to "Weather notification" that is used for retrieving weather information in Gadgetbride, just for pairing).

@Nlsalz

This comment has been minimized.

Copy link

commented Aug 9, 2019

@dj0001 got the auth key but can't get past GB's pairing stage. Just an unending loop. lol It does seem to connect to bluetooth but doesn't get through.

@vanous

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2019

@Nlsalz

This comment has been minimized.

Copy link

commented Aug 10, 2019

@vanous @dj0001 I've got it connected already. Yay!

@ashimokawa

This comment has been minimized.

Copy link
Contributor

commented Aug 10, 2019

The Python script is useful and all i would need to implement that in gadgetbridge.

Missing steps:

  • Actually implement sending signature in Gadgetbridge (easy)
  • converting the python script to a standalone android app , (medium) - volunteers?
  • make Gadgetbridge communicate with the to be written app mentioned above. (I don't want to have internet access and huami web service access in Gadgetbridge) - medium.
@unkraut

This comment has been minimized.

Copy link

commented Aug 16, 2019

To leave a short Feedback: Acquiring the authkey is a bit tricky. The authkey will be generated per Pairing. So Repairing on another device will lead into a wrong authkey. But after a sucsessful Connection, it works pretty good.

@fam4r

This comment has been minimized.

Copy link

commented Aug 16, 2019

To leave a short Feedback: Acquiring the authkey is a bit tricky. The authkey will be generated per Pairing. So Repairing on another device will lead into a wrong authkey. But after a sucsessful Connection, it works pretty good.

Uh, I think that's the reason why I didn't managed to pair the device after getting the key with the modded Mi Fit app.

@unkraut so what's the good path?

@unkraut

This comment has been minimized.

Copy link

commented Aug 16, 2019

@fam4r Just delete the Pairing on the old device in Android Settings and pair on the News device with Gadget-Bridge. Maybe also disabling Bluetooth on the old device could be a good Idea.

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