Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MoveNow - An AWS Lambda-based Fitbit Notifier

Why

The reason behind this example was that I needed to have a mechanism for reminding myself to regularly get some steps in every hour. While this feature is supported by newer Fitbit devices, my Fitbit Charge was missing the Reminders to Move function. My search for an approach to support this service without the need to manage servers etc. lead me to investigating AWS Lambda. AWS Lambda is a part of the AWS compute offering that lets one run code in response to events without having to provision or manage servers.

How does it work?

The process for getting the movenow notification occur through two related flows; see diagram below.

The first flow pertains to capturing steps data from the Fitbit device. This part occurs automatically when the device is paired with a smartphone running the Fitbit app. The device will sync periodically (approx. every 15 minutes) with the app and as long as the smartphone is Internet-connected it will upload the latest step data to the Fitbit server.

The second flow is what this example tackles. A scheduled rule is created in AWS CloudWatch to invoke an AWS Lambda function on an hourly basis. The AWS Lambda function retrieves step data from Fitbit servers and determines based on the step threshold value (i.e the minimum number of steps to take within an hour) if the user needs to be notified. If a notification needs to be sent, then the AWS Lambda function will use AWS Simple Notification Service (SNS) to send an SMS text through a predefined topic in SNS.

These two flows are depicted in the diagram below:

AWS Lambda call flow

Content

The source code is based on a NodeJS package structure and uses NPM to import libraries that facilitate certain core functions. The following are the key files needed:

  • src/lambda.js: The lambda function to transform the payload
  • package.json: Defines the packaging tasks and the npm modules in use

Requirements

Setting up the Components

  1. Define the AWS Lambda function
  2. Create Amazon Simple Notification Service (SNS) Topic through the console
  3. Create AWS CloudWatch event rule. The rule should define the frequency of execution through a schedule (fixed rate or Cron expression). The target should be the Lambda function created in Step 1 with the Configure Input having a JSON object containing the configuration object (event input values) of the function. The following is an example configuration:
{   
	"accessToken": "eyJhbGciOiJ",   
	"minHourlySteps": 250,   
	"snsTopicArn": "arn:aws:sns:us-east-1:999999999:movenow",   
	"snsTopicRegion": "us-east-1" 
}

Working with the source code

  • Clone or fork this repository
  • Ensure that you've followed the Requirements section above
  • Run npm run build to install dependencies, package the Lambda function and node modules in a zip and finally deploys the Lambda function to AWS using the AWS CLI.

###License

See LICENSE for further details.

About

MoveNow: An AWS Lambda-based Fitbit Notifier

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages