MMM-fitbit
MMM-fitbit copied to clipboard
Only displaying steps?
Hi, module installed and looking great. However, i'm only able to see steps, calories and mileage are both at 0. Any ideas?
Hi @toothie96, have you first checked online that the distance and caloiries are syncing with the fitbit site, then check if you enabled all the permissions when setting up the app?
Hi Sam! Just checked online and all is syncing up fine, all permissions are also enabled. Little bit stumped!
Try running getData.py from the python directory, it should print all the data
Doesn't seem to want to run - i've printed the errors below. I'm not entirely sure how to solve them either! I really appreciate your help though!
Traceback (most recent call last): File "/home/pi/MagicMirror/modules/MMM-fitbit/python/getData.py", line 2, in <module> import fitbit File "/home/pi/MagicMirror/modules/MMM-fitbit/python/fitbit/__init__.py", line 10, in <module> from .api import Fitbit, FitbitOauth2Client File "/home/pi/MagicMirror/modules/MMM-fitbit/python/fitbit/api.py", line 12, in <module> from requests_oauthlib import OAuth2, OAuth2Session ImportError: No module named 'requests_oauthlib'
Are you sure you ran sudo pip install -r python/fitbit/requirements.txt
from MMM-fitbit
folder?
I've just ran it again inside the MMM-fitbit folder, done a reboot, and the same errors are still present.
Run pip show --files requests-oauthlib
and check the version, if less that 0.8.0 try pip install --upgrade requests-oauthlib
.
Version is 0.8.0 and already up to date.
How bizarre, python should be able to find it. Maybe the best I can offer is a fresh install (back up your tokens and credentials) and see if the problem persists.
I've just done a fresh install and the problem is still there. Is there a way for me to manually add the numbers in? For example, can i take the output of steps, divide this by 2000 (the average amount of steps in a mile) and then the output of this to be displayed in the mileage field? And the same for calories?
That is very strange. But yes, custom calculations are possible. Alter python/getData.py
so that print_data(resource, value, goal)
has the custom values for each resource you want to alter. Steps, floors, and calories are handled by a for loop and distance, active minutes, sleep time, and resting heartrate are handled after. Adapt these are required.
Hi there, Just adding my own experience to this issue. I've encountered exactly the same problem as described by toothie96 (only steps displaying, all other parameters syncing correctly but "0" on the MagicMirror). Before reading this issue I've reinstalled the module, change tokens and credentials, etc... but no luck so far! @SVendittelli: Let me know if I can provide you with a specific information that may help to solve this issue. Best, Lou Gouyat
More info, hope this can help: Here is the 'total' answer to the "sudo python getData.py" command:
{"message": "credentials.ini exists", "type": "status"} {"message": "Reading from credentials.ini", "type": "status"} {"message": "Read of credentials.ini successful.", "type": "status"} {"message": "credentials.ini exists", "type": "status"} {"message": "Reading from credentials.ini", "type": "status"} {"message": "Read of credentials.ini successful.", "type": "status"} {"message": "tokens.ini exists", "type": "status"} {"message": "Reading from tokens.ini", "type": "status"} {"message": "Read of tokens.ini successful.", "type": "status"} {"message": "Making API call", "type": "status"} {"message": "API call okay", "type": "status"} {"message": "Tokens valid", "type": "status"} {"values": {"data": 6932, "goal": 6000}, "resource": "steps", "type": "data"} {"values": {"data": 0, "goal": 1}, "resource": "floors", "type": "data"}
*** Why it is stopping at the resource 'floors' and not going further ('caloriesOut', 'distance', 'activeMinutes', 'sleep', 'heart')? ***
Moreover the 'total' answer to the "pip show --files requests-oauthlib" command is:
Name: requests-oauthlib Version: 0.8.0 Location: /usr/local/lib/python2.7/dist-packages Requires: oauthlib, requests Files: Cannot locate installed-files.txt
I hope this helps to solve the problem. Lou Gouyat
I'm looking at the getData.py file now and i'm struggling to work out where to place the custom calculations. Could you possibly help me place them?
The two calculations I'm looking to implement are...
Distance = 'steps' (divide) 2000 CaloriesOut = 'steps' (divide) 20
@toothie96 Lines 40-46, you'll have to remove the for loop. Something like this:
print_data('caloriesOut', activitySummary[steps] / 200, activityGoals[resource])
print_data('distance',activitySummary['steps'] / 2000,activityGoals['distance'])
@TitouBilou It looks like there is a problem with one of the print_data()
statements (probably distance). So either it isn't retrieving the value or the goal. Try replacing some of those values with hard coded ones to see which values it is struggling with. Or adding print statments for all of activitySummary
to make sure it has the right JSON format.
@SVendittelli If you think that the problem comes from the fact that it isn't retrieving the value for 'distance', could it be linked to the decimal separator. I live in France and we use the comma as decimal separator (see the screen capture below). Is the comma creating some problem retrieving the distance value? (might be a stupid idea, but I'd better ask just in case....?).
By the way I changed "mi" by "km" in the module.js file for a proper display of 'distance'
@TitouBilou That is a good point, that maybe the culprit. I know you can set a locale in the request header but it should default to METRIC as I haven't set it.
@SVendittelli What code and in which file should I set up the locale (sorry I am not good enough...). I bet it is not in METRIC as it displays 6,932 steps on the MagicMirror. It should be 6 932 (without the comma) as shown on the screen capture above.
@SVendittelli By the way in the getData.py file, the print_data (distance) line is: *** print_data('distance',activitySummary['distances'][0]['distance'],activityGoals['distance']) *** Is the "activitySummary['distances'][0]['distance']" correct ou should it be "activitySummary['distance'][0]['distance']", without the "s" at ['distance'][0]
@TitouBilou If you manage to find a resolution to this please let me know, this mirror is being given as a 21st present to my partner this friday, and i'm struggling to even add my own custom calculations, so if a fix was possible that'd be great! Cheers.
@TitouBilou The API response is without a thousands separator, but I don't know how it localises the decimal separator.
https://dev.fitbit.com/docs/activity/
I also think it is "distances", not "distance" from the example response above.
@toothie96 I'll let you know if I find an answer but I do think in my case that it is a locale problem and it cannot retrieve the distance value (the only decimal parameter).
@SVendittelli I'll check the document but I do really think the decimal separator is the problem (there is no reason to display the number of steps with a comma when it's not displayed on the fitbit dashboard).
Best,
@SVendittelli I read the documents https://dev.fitbit.com/docs/activity/ and https://dev.fitbit.com/docs/basics/ The problem could be due to 'Accept-Locale' and not the 'Accept-Language' (as you already mentioned, when nothing is indicated, METRIC is used by default). ['Accept-Language' is for units such as miles versus kilometers as 'Accept-Locale' concerns the response format, comma versus dot most likely...] There is a series of formats supported by fitbit for 'Accept-Locale', including the fr_FR which could perhaps solve my problem. Now, How do I set 'Accept-Locale' to 'fr_FR' in the request header and in which file? This might sound dull to you but I am unfortunately not good enough to set this command line (learning is a long process...) Thanks in advance, Best,
@TitouBilou That is the challenging bit, the python-fitbit
client I use does not currently support the Accept-Locale
header. You might be able to do a hacky fix by adding that header to every request you make to the API (this might break everything, I don't know). You can do this by editing /python/fitbit/api.py:224
to include the 'Accept-Locale': 'fr_FR'
.
Alternatively, change the same line to have 'Accept-Language': self.system
hard coded as 'en_US'
.
I am in the UK so I'll be using en_GB
by default.
@SVendittelli Thanks for your help. I am trying different options on your advice... no luck so far but I'll keep trying and keep you posted if I succeed. Best,
@SVendittelli & @toothie96 Sorry guys but I am giving up. I've tried many combinations (even relocalising the fitbit account in the US and UK!), but I am still unsuccessful... That's it for me, not competent enough to pursue the quest... Sorry, Best,
@TitouBilou: I found out that if you remove 'floors' from the ResourceTypes in the file getData.py then I get more information from fitbit like caloriesout and distance. Original line: ResourceTypes = ['steps', 'floors', 'caloriesOut'] Changed line: ResourceTypes = ['steps', 'caloriesOut'] But I still miss some things like heartbeat etc. Maybe some more experienced developer can continue with this and find out why floors doesn't work.
Best,