miband4 icon indicating copy to clipboard operation
miband4 copied to clipboard

connection issue

Open FransM opened this issue 4 years ago • 11 comments

I' seem to have connection issues.

From the log: 2019-12-31 16:05:05,769 miband (INFO) > Connecting to FC:D1:E0:EF:5D:0D 2019-12-31 16:05:07,210 miband (INFO) > Connected Connection to the MIBand failed. Trying out again in 3 seconds 2019-12-31 16:05:49,537 miband (INFO) > Connecting to FC:D1:E0:EF:5D:0D 2019-12-31 16:05:56,350 miband (INFO) > Connected

I've added some trace code and it seems to be failing in miband.py at this line: self.svc_1 = self.getServiceByUUID(UUIDS.SERVICE_MIBAND1)

The weird thing is: I had it working twice: The first time was the very first time I used the program (without giving the key). After that I got the above. Reset did not work, reboot did not work.

And then after instrumenting the code I started it again, It ran into this connection cycle. I went away and after some time lo and behold the curses UI was there. As I was busy with somehing else I only tried a few commands> last one was the music one. Then I was AFK for a while again, and when I came back I encounterd a crash. Not sure if that one is related to the connection issue but the backtrace is:

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/usr/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.6/dist-packages/cursesmenu/curses_menu.py", line 133, in _wrap_start curses.wrapper(self._main_loop) File "/usr/lib/python3.6/curses/init.py", line 94, in wrapper return func(stdscr, *args, **kwds) File "/usr/local/lib/python3.6/dist-packages/cursesmenu/curses_menu.py", line 193, in _main_loop self.process_user_input() File "/usr/local/lib/python3.6/dist-packages/cursesmenu/curses_menu.py", line 289, in process_user_input self.select() File "/usr/local/lib/python3.6/dist-packages/cursesmenu/curses_menu.py", line 329, in select self.selected_item.action() File "/usr/local/lib/python3.6/dist-packages/cursesmenu/items/function_item.py", line 35, in action self.return_value = self.function(*self.args, **self.kwargs) File "miband4_console.py", line 160, in set_music if band.waitForNotifications(0.5): File "/usr/local/lib/python3.6/dist-packages/bluepy/btle.py", line 560, in waitForNotifications resp = self._getResp(['ntfy','ind'], timeout) File "/usr/local/lib/python3.6/dist-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.6/dist-packages/bluepy/btle.py", line 362, in _waitResp raise BTLEDisconnectError("Device disconnected", resp) bluepy.btle.BTLEDisconnectError: Device disconnected

Restarting the program again brings me into the connect loop mentioned above. (and this is all on a mi band 4 if that matters, not a 3 or so)

FransM avatar Dec 31 '19 15:12 FransM

bit of additonal info: I also instrumented to have a call to getServices() just before it fails and iterate over the services but that one also fails often (I had one more successful run of the program)

FransM avatar Dec 31 '19 15:12 FransM

I have the same problem, I suspect it may be fimware, what is your version of fimware? and your @satcar77

Adejair avatar Jan 15 '20 11:01 Adejair

The same thing is happening with me. The menu works only for items that don't require the AUTH_KEY (eg. device info). I used the freemyband APK to get the AUTH_KEY.txt, so I'm at a loss as well

marto68 avatar Jan 22 '20 07:01 marto68

It turns out that in my case it was an issue with getting the correct AUTH_KEY with freemyband. I went through it again and now it works fine. Thanks so much, now the fun begins :)

marto68 avatar Jan 23 '20 19:01 marto68

@Adejair @FransM Sorry for the late reply. I was really busy and couldn't check out. I never encountered this kind of issue and the code still works fine for my Miband. The debug log that was posted wasn't particularly helpful for me to find the exact cause of the problem. I couldn't pinpoint the cause of such an error. However, I have added a few tweaks to the code which I hope will help to counteract this issue. Please pull the latest commit and try it out.

@Adejair I don't think that the issue is due to the firmware. Here is my device info: Soft revision: V1.0.9.22 Hardware revision: V0.25.131.5

Thank you

satcar77 avatar Feb 17 '20 10:02 satcar77

Hey, just wanted to add that I'm trying this project on my raspberry pi and to execute the program such that you don't get this issue, you need to use sudo. So the command becomes: sudo python3 miband4_console.py -m #MAC_ADDRESS

Naman1997 avatar Mar 27 '20 19:03 Naman1997

Hello, thank you for this great job. I found out that my mi band 4 can connect with my pc only with unauthorized features. I got the auth_key using huami-token method ### Logging in with Xiaomi account.

When i got be connected and try the option 2 - @ Get Steps/Meters/Calories/Fat Burned
this exception is initiated

Exception in thread Thread-1: Traceback (most recent call last): File "/home/taniel/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/home/taniel/anaconda3/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/taniel/anaconda3/lib/python3.7/site-packages/cursesmenu/curses_menu.py", line 133, in _wrap_start curses.wrapper(self._main_loop) File "/home/taniel/anaconda3/lib/python3.7/curses/init.py", line 94, in wrapper return func(stdscr, *args, **kwds) File "/home/taniel/anaconda3/lib/python3.7/site-packages/cursesmenu/curses_menu.py", line 193, in _main_loop self.process_user_input() File "/home/taniel/anaconda3/lib/python3.7/site-packages/cursesmenu/curses_menu.py", line 289, in process_user_input self.select() File "/home/taniel/anaconda3/lib/python3.7/site-packages/cursesmenu/curses_menu.py", line 329, in select self.selected_item.action() File "/home/taniel/anaconda3/lib/python3.7/site-packages/cursesmenu/items/function_item.py", line 35, in action self.return_value = self.function(*self.args, **self.kwargs) File "miband4_console.py", line 80, in get_step_count binfo = band.get_steps() File "/home/taniel/mb4/miband4/miband.py", line 274, in get_steps a = char.read() File "/home/taniel/anaconda3/lib/python3.7/site-packages/bluepy/btle.py", line 197, in read return self.peripheral.readCharacteristic(self.valHandle) File "/home/taniel/anaconda3/lib/python3.7/site-packages/bluepy/btle.py", line 530, in readCharacteristic resp = self._getResp('rd') File "/home/taniel/anaconda3/lib/python3.7/site-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/home/taniel/anaconda3/lib/python3.7/site-packages/bluepy/btle.py", line 368, in _waitResp raise BTLEGattError("Bluetooth command failed", resp) bluepy.btle.BTLEGattError: Bluetooth command failed (code: 2, error: Attribute can't be read)

thank you for any help

tanielfranklin avatar Jul 17 '20 01:07 tanielfranklin

@tanielfranklin This error shows up for unauthorized read of heartrate and other sensitive information. The auth key that you are using has to be wrong. Please try retrieving your auth_key using the methods in this website : https://www.freemyband.com/

satcar77 avatar Jul 17 '20 03:07 satcar77

@tanielfranklin This error shows up for unauthorized read of heartrate and other sensitive information. The auth key that you are using has to be wrong. Please try retrieving your auth_key using the methods in this website : https://www.freemyband.com/

Thank you for a fast reply. I suspected of wrong auth_key too. Unfortunately the freemyband method doesn't work to my band. I can't because no mi fit app can be paired. I think is necessary a hard reset or unlink this band from the server. The server is giving me a useless auth_key through huami-token method.

tanielfranklin avatar Jul 18 '20 11:07 tanielfranklin

@tanielfranklin This error shows up for unauthorized read of heartrate and other sensitive information. The auth key that you are using has to be wrong. Please try retrieving your auth_key using the methods in this website : https://www.freemyband.com/

Thank you for a fast reply. I suspected of wrong auth_key too. Unfortunately the freemyband method doesn't work to my band. I can't because no mi fit app can be paired. I think is necessary a hard reset or unlink this band from the server. The server is giving me a useless auth_key through huami-token method.

I tried pair it with other accounts and other phones too.

tanielfranklin avatar Jul 18 '20 12:07 tanielfranklin

Hi!

I can't connect to miBand4 with firmware version 1.0.9.66. I've activated the visibility in the official app, and lescan gets the MAC. git_miband4

Regards

joseaguardia avatar Sep 24 '20 20:09 joseaguardia