creotiv / MiBand2

Library to work with Xiaomi MiBand 2
Creative Commons Zero v1.0 Universal
544 stars 173 forks source link

Python3 - code for recorded hangs #40

Open OldShaterhan opened 4 years ago

OldShaterhan commented 4 years ago

Hey guys, I'm running instance of this code, but unfortunately, for some reason when I run it in Python3 for old data (-r switch) it suddenly hangs on random date and time and doesn't finish it work. When I break it by Ctrl+C from traceback I see it hangs on band.waitForNotifications(0.1), what executes btle.py line 560, then 407 and 342. Have anyone idea how to solve this issue?

creotiv commented 4 years ago

Did you try to change start date? https://github.com/creotiv/MiBand2/blob/master/example.py#L34

OldShaterhan commented 4 years ago

Hmm... I'm quite new to Python, and my source bases on this solution (small changes), but - to be specific - I just reinitated the device, so it doesn't have new records (for instance - now i have records from Jan 26th, 19:50 local time, and it gained records up to 20:57 local time (now it's 21:18).

For Python2 it worked properly, but when I changed code (basing on changes here and some that I did earlier) to work with Python3, then it hangs on fds = self._poller.poll(timeout*1000)

Anyway, I will change start date in few minutes, as I'm going to replace it with some more actual date.

OldShaterhan commented 4 years ago

I replaced it and now it hanged on 20:53 on first attempt, again 20:57 on second one. Start date at this moment is 01.12.2019 01:01.

I see similar issue when I'm trying to use get_heart_rate_one_time - measurement is finished, but source again hangs on the lines (560->407->342) of bluepy/btle.py, but this error occurs also on Python2.7

creotiv commented 4 years ago

BluePy not the best Bluetooth lib, there are many problems with it, but also maybe something with packets. I will assign this to the guy who made this function(cause I lost my band a long time ago)

creotiv commented 4 years ago

@FHantke Can you help to solve this issue? Thanks

OldShaterhan commented 4 years ago

Coming back to HR - after few hours now in few iterations it was measured properly, but steps hanged e.g. on 2:21 AM, but this only applies to the Python3 version, with the older one everything was fine.

Thanks.

Edit: One more thing that can be a bit interesting - I'm running it on RPi Zero WH.

OldShaterhan commented 4 years ago

Another update: I got opportunity to test original code on MB2 - issue still exists :/

FHantke commented 4 years ago

hey, I'll check it out if I find the time. Haven't used MB in a while. Keep me up to date, when you fix the issue :)

OldShaterhan commented 4 years ago

@FHantke I'm not quite good in Python, but if I'll find something I'll let you know. However I need this ASAP, anyway thanks :D

OldShaterhan commented 4 years ago

Another update: now HR obtaining works for only one device, on second not.

OldShaterhan commented 4 years ago

Well, I'm testing it again and again and I found one thing that may interest you:

For device initialized by this date: ISODate("2020-01-26T21:31:00.000Z") (this is my local time, not UTC actual), with start date before that date then records are available till 22:55. When I'll try fetch data from exactly that date (i.e. 2020-01-26T22:55), only one record is obtained and code freezes. When I change it to next minute (i.e. 2020-01-26T22:56) - I'm getting records up to 2020-01-27T12:08 and library freezes again.