The potential of wearable devices

The market of wearable devices is one of the most active of the IoT markets. According to IDC, it has already generated a year over year growth of 30% in 2015 and it is forecast to result in a five-year compound annual growth rate of 45.1% in 2019.

What is interesting about wearable devices is that they enhance the user’s awareness about himself and his physical condition. From a development perspective, this is a great opportunity as leveraging data that is sent by wearable devices can lead to many possible applications: from creating a virtual coach that follows-up on user’s performance and adapts his training accordingly, to an application that connects to a map service to suggest the best track to improve your performance, the possibilities are numerous.

Use scriptr.io to leverage the opportunities raised by wearable devices

Collecting and receiving user’s data is a first step, but what is next? What is needed is to transform and leverage this data to produce information, take decisions and more generally, produce added value. This is where scriptr.io comes in handy, thanks to its orchestration and integration capabilities, its useful APIs and its persistence layer.

scriptr.io’s connector to Fitbit

At scriptr.io, we like staying in shape (mens sana in corpore sano) and we foster sports and physical activities – especially the days after we had a party around the company’s pool 😉
As a consequence, many of us own a Fitbit tracker (Fitbit has been leading the market of wearable devices for a while now) to follow-up on their physical performance and use scriptr.io and Fitbit’s APIs to implement their own bespoke fitness application. We figured out that this would also be the case for many developers and development teams out there, this is why we unleashed our Fitbit connector, that wraps most of Fitbit’s APIs and expose them through a bunch of JavaScript objects that you can directly use in your own scriptr.io scripts.

Example: effort-related meal suggestions

In this very simple example, we will use scriptr.io’s Fitbit connector to retrieve the calories that were spent by a given user. Based on this value, our script will invoke a recipe API (Food2Fork) in order to retrieve an appropriate set of recipes (few calories spent –> grilled fish, many calories spent –> grilled meat). The recipes are returned as a list of JSON objects.

Note: In the below, we consider that we already obtained an authorization token for the given user. Kindly refer to the README.md file for more on how to obtain such a token.

// require the fitbit userClient module (fitbit connector)
var userClient = require("modules/fitbit/userClient.js");
// require the http module (allows you to invoke 3rd party APIs)
var http = require("http");
// Create an instance of user (we assume the user exists and we already obtained an authorization token for him)
var user = new userClient.FitbitUser({username:"bob"});
// get how many calories were spent today
var totalCalories = user.getSpentCalories({"fromDate": "today", "toDate": "today"})
console.log("So far you spent " + totalCalories.total + " kcal today");
if (totalCalories.total < 950) {
  ingredients = "grilled fish";
}else {
  ingredients = "grilled meat";
}
// build the request to the recipe API (replace the value of the 'key' parameter below with your own Food2Fork API key)
var recipeApiUrl = "http://food2fork.com/api/search?key=6b7ba2f46ee9810g2ff7vf069e4k98f4&q=" + encodeURIComponent(ingredients);
// invoke the recipe API
var params = {
"url": recipeApiUrl
}
var result = http.request(params);
// return the result of the invocation, in JSON format
return JSON.parse(result.body);