Skip to content

This application is a heart rate measurement tool using Fitbit. Heart rate is analyzed using Fitbit API, and notification is sent to LINE talk room if threshold is exceeded.

Notifications You must be signed in to change notification settings

naomichi-y/dokidoki_watch

Repository files navigation

dokidoki watch

This application is a heart rate measurement tool using Fitbit. Heart rate is analyzed using Fitbit API, and notification is sent to LINE talk room if threshold is exceeded.

Architecture

Applications are configured in a serverless architecture and work on AWS Lambda.

Required tools

The development environment can be built with Docker.

Docker components

Docker consists of the following containers.

  • dokidoki_watch-app container

  • dokidoki_watch-db container

    • MySQL v5.7

Setup

Create Fitbit application

Please open dev.fitbit.com and create a new application. OAuth 2.0 Application Type must be set to Personal.

Create development environment

$ docker-compose build
$ docker-compose up

# For application settings, please edit `config/default.json` (or `development.json`, `production.json`).
$ npm run sequelize db:migrate

Open the http://localhost:3000/ in your browser. In API console, you can try the Fitbit API.

If you want to start Express without going through Docker, please execute the following command.

$ npm run watch

Deploy to AWS

Deploy flow is same as aws-serverless-express package.

Initial setup

Create a stack with CloudFormation.

$ mysql -u {USER} -p -h {HOST} -e "CREATE DATABASE {DATABASE}"
$ npm run sequelize -- --env production db:migrate

$ npm run config <accountId> <bucketName> [region]
$ npm run setup

Lambda trigger settings

Unfortunately, CloudFormation does not support scheduled Lambda events. Trigger must be set manually.

  1. Open DokiDokiWatchHeartrateChecker function on Lambda console.
  2. Open the Triggers tab.
  3. Open the Triggers tab and click Add triger.
  4. Set trigger properties.
  • Trigger type: CloudWatch Events - Schedule
  • Schedule expression: rate(5 minutes)
  • Enable trigger: Check

This completes the setting.

Lambda VPC settings

Also, in order to connect to MySQL from Lambda, we strongly recommend VPC setting of Lambda function (VPC setting is not done in above setup)

Create database

You need to create a database first. Please match name specified in config/database.json.

Test drive

Please synchronize Fitbit. If application is set up correctly, you can check the execution result on CloudWatch Logs.

Updating Lambda function

$ npm run package-upload-update-function

Deleting stack on CloudFormation

$ npm run delete-stack

About

This application is a heart rate measurement tool using Fitbit. Heart rate is analyzed using Fitbit API, and notification is sent to LINE talk room if threshold is exceeded.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published