A script to fetch data from Fitbit servers using their API and store the data in a local influxdb database.
- Create a new influxdb v2 bucket and token
- Installation instructions for influxdb can be found at InfluxDB Install Docs
- Install grafana if not already available
- Install python dependencies (within a venv if required):
python3 -m pip install -r requirements.txt
- Create a fitbit application using the fitbit getting started guide
- Many fields can be filled in arbitrarily. However the "OAuth 2.0 Application Type" must be set to
personal
and the "Redirect URL" needs to behttp://localhost:4444
(the port number can be changed. Ensure its updated in the .env file as well)
- Many fields can be filled in arbitrarily. However the "OAuth 2.0 Application Type" must be set to
- Edit the
.env
file with the required settings - On a computer with a web browser, run the token-helper.py script. This will generate the inital
refresh token
and saved to the given file path. A web browser is required for the OAuth authorization- If the intent is to run this script on a headless server, copy the resulting
token
file to the server
- If the intent is to run this script on a headless server, copy the resulting
- Add the influx database as a datasource in Grafana (if required)
- Install these two panel plugins
- Import the
Health Stats Dashboard.json
dashboard into grafana. Change the datasource to your influx database and alter thebucket
variable (located at the top of the dashboard after importing) to the previously created bucket
You can use the Fitbit_Fetch_Autostart.service template to set up an auto-starting ( and auto-restarting in case of temporary failure ) service in Linux based system ( or WSL )
Run the script; if the token
file does not exist, the script will request a refresh token as input and then will set up the token file. You can check the logs to see the work in progress. The script, by default, keeps running forever, calling different functions at scheduled intervals.