Fitboard.me is a webapp built to connect the Fitbit API to Panic's Status Board iPad application. Fitboard is free for anyone to use at Fitboard.me or you can fork the repo and build your own.
The source for Fitboard is open - please contribute.
Fitboard allows you to visualize
- Steps
- Calories
- Distance
- Floors
- Active Score
- Minutes Asleep
- Sleep Efficiency
- Times Awakened
- Minutes Sedentary
- Minutes Lightly Active
- Minutes Fairly Active
- Minutes Very Active
And a multi point graph showing
- Minutes Sedentary
- Minutes Lightly Active
- Minutes Fairly Active
- Minutes Very Active
Over
- 1 Day
- 7 Days
- 1 Month
- 3 Months
- 6 Months
- 1 Year
- Max
In Status Board on your iPad
Fitboard depends heavily on the following awesome Python packages:
You can see the full list of packages in requirements.txt
You should be able to deploy Fitboard locally, to a VPS or on Heroku with minimal configuration changes.
Use Virtualenv Wrapper to manage virtual environments
Create a new virtual environment
mkvirtualenv fitboard
cd ~/Projects
git clone https://github.com/ctaloi/Fitboard.git
cd ~/Projects/Fitboard
workon fitboard
pip install -r requirements.txt
Set your config.py file for local SQLite
# if sqlite, uncomment the next two lines
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
# else
# SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']
In order to talk to the Fitbit API you need to sign up and obtain a key and secret.
Completing the registration request is easy.
- Default access type: Read-Only
- Application Type: Browser
Save your CONSUMER_KEY and CONSUMER_SECRET
Install Heroku Toolbelt
Follow the Getting started with Flask and Heroku guide for setting up your Heroku Deployment
Add Postgres addon
heroku addons:add heroku-postgresql:dev
Promote the database
heroku pg:promote HEROKU_POSTGRESQL_TEAL_URL
This sets up Postgres and sets the heroku config DATABASE_URL for us. To create and populate the database table we need to use a heroku python shell
heroku run python
>>> from main import db
>>> db.create_all()
You can use this Postgres instance locally or deployed
Flask can also run under a standalone WSGI container - more detail and options
I've tested with the following stack:
Basically - Supervisor starts Gunicorn who starts the fitboard app
config: /etc/supervisor/conf.d/fitboard.conf
[program:gunicorn]
command=/home/fitboard/.virtualenvs/Fitboard/bin/gunicorn -w 4 -b 127.0.0.1:8000 main:app
directory=/home/fitboard/fitboard
user=fitboard
autostart=true
autorestart=true
redirect_stderr=True
environment=CONSUMER_KEY="XXX",CONSUMER_SECRET="XXX",DATABASE_URL="XXX",SECRET_KEY="XXX"
config: /etc/nginx/sites-available/fitboard (symlink in sites-enabled)
server {
listen 80;
server_name fitboard.me;
access_log /var/log/nginx/fitboard.log;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Gunicorn is configured in the supervisor config file
- Edit config.py and set debug to True
To start Fitboard running under Flask debug mode (local - non production) you need to setup your environmental variables using the CONSUMER_KEY and CONSUMER_SECRET provided by Fitbit and other 'secure' variables of your deployment.
I have a shell script which runs the following
export CONSUMER_KEY=
export CONSUMER_SECRET=
export DATABASE_URL=
export SECRET_KEY=
export MAIL_USERNAME=
export MAIL_PASSWORD=
./python main.py
Set your variables using the Heroku CLI
heroku config:set SECRET_KEY=
heroku config:set CONSUMER_KEY=
heroku config:set CONSUMER_SECRET=
heroku config:set MAIL_USERNAME=
heroku config:set MAIL_PASSWORD=
heroku config:set DATABASE_URL=
Your environmental variables are called in the your supervisor config
config: /etc/supervisor/conf.d/fitboard.conf
[program:gunicorn]
command=/home/chris/Envs/fitboard/bin/gunicorn -w 4 -b 127.0.0.1:8000 main:app
directory=/home/chris/Projects/Fitboard
user=chris
autostart=true
autorestart=true
redirect_stderr=True
environment=CONSUMER_KEY="XXX",CONSUMER_SECRET="XXX",DATABASE_URL="XXX",SECRET_KEY="XXX"
service nginx restart
service supervisor restart
Supervisor will trigger Gunicorn and Fitboard