Development
My Favorite Open-Source Projects for Fitbit Development
By Brandon Him
May 13th, 2020
If you know anything about me, I'm a huge advocate of open-source development. In my past life (prior to a family), I would spend every weekend at a coffeeshop building open-source projects. Overtime, I gathered over half a million downloads in my open-source projects and over 1,000 stars on GitHub.
Honestly, it's extremely rewarding helping others achieve at scale, especially when you combine it the community -- the end user benefits the most from it.
Now enough of my scpheil, here are my personal favorite OOS repositories for developing sound and robust Fitbit watchfaces and applications.
FitFont by gregoiresage
🚀 Donate to gregoirsage @ paypal.me/gsage
fitfont
is by far my personal favorite and is truely under appreciated.
If you are new to Fitbit development, you'll discover that custom fonts are a typical challenge as you need to generate individual images per a letter. However, this repository automates that process and creates a widget for you to use quickly.
Also, it contains an API familiar to the text element but with some pretty neat extras like horizontal alignment and letterspacing.
Example Code
import { FitFont } from 'fitfont'
const statLabel = new FitFont({
id: 'stat-label',
font:'Open_Sans_20',
halign: 'start',
valign: 'middle',
letterspacing: -1
});
statLabel.text = 'Steps'
fitbit-views by SergioMorochon
fitbit-views
is a simple, yet powerful module for navigating between views in your Fitbit applications. You can think of it as a router module similar to what you would typically use for any SPA application.
Example Usage
import { setup, next } from 'fitbit-views';
import HelpPage from './views/HelpPage';
import ListPage from './views/ListingPage';
setup({
'help': HelpPage,
'list': ListPage,
});
document.getElementById('helpButton').onactivate = () => {
next('help');
};
fitbit-asap by dillpixel
Despite the drastic improvements on the messaging API (thanks to project Golden Gate), Fitbit developers all know that the messaging API is still rather finicky.
This is where fitbit-asap
comes along, it's an added level of reliability by abstracting the handling of retransmits -- kind of like TCP. It also has an easy API that is identical for both companion and device side with three main API methods: send
, onmessage, and
cancel
.
Example Code
Device (App Side)
import asap from "fitbit-asap/app";
asap.send("Knock, Knock");
asap.onmessage = message => {
if (message === "Whose there?") {
asap.send("Chicken");
}
if (message === "Chicken Who?") {
asap.send("Chicken Butt!!");
}
}
Companion
import asap from "fitbit-asap/companion";
asap.onmessage = message => {
if (message === "Knock, Knock") {
asap.send("Whose there?");
}
if (message === "Chicken") {
asap.send("Chicken Who?");
}
}
My apologies for 1st grade humor. :)
fitbit-weather by gregoiresage
By far one of our biggest feature request is weather support on watchfaces. However, instead of building out your own weather component, you really should be using a module that is robust and well-tested, this is where fitbit-weather
comes into play. fitbit-weather
is a library that allows you to pull weather data to display on your Fitbit watchface. It handles the geolocation, conversions of temperature between F and C, and supports 3 big weather providers.
Example Code
Companion
import * as weather from 'fitbit-weather/companion';
const config = {
provider: weather.Providers.openweathermap,
apiKey : 'YOUR_KEY'
};
weather.setup(config);
App
import * as weather from 'fitbit-weather/app';
weather.fetch(30 * 60 * 1000)
.then(weather => {
document.getElementById('farenheit').text = weather.temperatureF;
})
.catch(error => console.log(JSON.stringify(error)))
Conclusion
These are my personal picks of open-source modules for Fitbit, and I hope they accelerate your development efforts.
One thing I do want to note is that for every open-source module you use, there were many people behind the scenes spending the hours to build it. One of the harsh reality is open-source is unsustainable for the majority of authors, so if you can please sponsor, contribute, or donate to the authors.