A Fitbit Low Battery SMS Notification using AWS – Part 3

In Part 1, I introduced an app that sends an SMS notification when your Fitbit battery is low. Part 2 covered the Authentication Flow of the process. This post describes how the device status is checked and communicated to the user.

Fitbit-SMS-Sched2The flow is as follows:

  1. The CloudWatch Scheduler kicks off a Lambda job that pulls registered users from the DynamoDB table. This information is based to a SNS topic, which in turn…
  2. …kicks off the Lambda function that obtains the Fitbit device info. The Fitbit api is called, and the resulting message is processed by the Lambda function. The device information is stored in and retrieved from the DynamoDB table as needed for processing and history tracking.
  3. If the result was a success then the a message is sent to the SNS topic for the subscribed user – assuming that the battery status is low AND the user has not already been notified.
  4. If a “Token Expired” error is returned, then the Lambda function passes the required information to the Refresh User SNS topic. The Lambda function again calls a Fitbit API; this time to refresh the token.
  5. If the token is refreshed, then the information is saved to the DynamoDB table and passed to the Get Device Info Topic (starting the process all over again)
  6. If a failure occurs, then a message is sent to the user, directing them to re-authorize the application to access their Fitbit account.

Continue reading “A Fitbit Low Battery SMS Notification using AWS – Part 3”

A Fitbit Low Battery SMS Notification using AWS – Part 2

In Part 1, I introduced an app that sends an SMS notification when your Fitbit battery is low. Part 2 covers the Authentication Flow of the process.

Fitbit-SMS-Auth

The flow is as follows:

  1. User accesses the sign-up page (and by default, provides authorization via Fitbit.com). The request is passed through an API Gateway to a Lambda function. The Lambda function calls a Fitbit api to authenticate the user.
  2. The Fitbit authentication returns to the Lambda code. From there: (3) the token is saved to a DynamoDB database, (4) a message is placed on a SNS topic, and (5) a success response is sent back to the webpage
  3. The user information (access_token, refresh_token, and mobile number) is saved to a DynamoDB table
  4. An SNe1079abb478cc4e04d13615bc10aa4ca[1]S topic receives the mobile number as a message
  5. A success message is sent back to the end user.
  6. The SNS topic (step 4) calls a second Lambda function.
  7. The Create_User_Topic lambda function creates a sns topic for the newly authenticated user.
  8. Once the topic is created, a notice is sent to the user’s mobile device – asking to confirm subscription.
  9. The user confirms the subscription.

Continue reading “A Fitbit Low Battery SMS Notification using AWS – Part 2”

A Fitbit Low Battery SMS Notification using AWS – Part 1

765a3f73cd8c5b0c0bc96bc3cd094740[1]

A few weeks ago, my Fitbit (one of my new favorite devices) died.

Not died, as in bricked; my battery died.

That was a bit surprising, as I am signed up for low battery notifications. Turns out, I did get a notice – in an email. Problem was, I wasn’t checking my email that day.1

fitbit_notificationThe next day, I went back to the Fitbit website to sign-up for SMS notifications; unfortunately, Fitbit doesn’t provide a low battery notification via SMS.

So, I built my own, using a handful of AWS services (Lambda, SNS, API Gateway, and DynamoDB) and exposed Fitbit APIs.

So far, it works well. After subscribing to the service, I got an introductory note telling my my battery status. A few hours later, I received a second notice – letting me know that my battery was low. Continue reading “A Fitbit Low Battery SMS Notification using AWS – Part 1”