creotiv / MiBand2

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

Heart Rate plotting error #11

Closed Mr5quid closed 6 years ago

Mr5quid commented 6 years ago

Hi,

I'm toying around with your lib but I can't get the plotting to work. Dumping raw data worked well but when trying to plot the results I get theses errors.

Traceback (most recent call last): File "plot.py", line 16, in <module> df.rolling(120).mean().plot() File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 2941, in __call__ sort_columns=sort_columns, **kwds) File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 1977, in plot_frame **kwds) File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 1804, in _plot plot_obj.generate() File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 266, in generate self._post_plot_logic_common(ax, self.data) File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 404, in _post_plot_logic_common fontsize=self.fontsize) File "/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.py", line 478, in _apply_axis_properties labels = axis.get_majorticklabels() + axis.get_minorticklabels() File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1245, in get_majorticklabels ticks = self.get_major_ticks() File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1396, in get_major_ticks numticks = len(self.get_major_locator()()) File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1249, in __call__ self.refresh() File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1269, in refresh dmin, dmax = self.viewlim_to_dt() File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1026, in viewlim_to_dt .format(vmin)) ValueError: view limit minimum -0.001 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units Soft revision: V1.0.1.81 Hardware revision: V0.1.3.3 System : Debian Stretch

Do you have any thoughts ?

creotiv commented 6 years ago

Do you have measurement for 120 seconds in the dump file? Also try to replace last line with: df.rolling('120s').mean().plot()

Mr5quid commented 6 years ago

Thanks for pointing that out! I didn't know a minimal time was required. Also it's more relevant to say 120 entries because I almost never have 1 entry per second during acquisition. My connection doesn't seem stable seeing as it the device can skip more than 5 seconds in a row. In fact it took me around 4 minutes to get 140 lines in the dump file.

I did try to wait for more than 2 minutes earlier but I constantly got disconnected until I commented out the call to bluepy.btle.Peripheral.disconnect() in dump.py at line 26. Why is this line present in the code ?

creotiv commented 6 years ago

Because it working in a loop, device can sometime broke giving sensor data and in such situation it will be disconnected, and then reconnected.

Mr5quid commented 6 years ago

I see. I might have an issue with my bluetooth driver then. I was almost never able to reconnect after a disconnection. Removing the line seems to make the link more reliable.