Using AWS IOT To Arm Blink Cameras

Posted on Sat 16 December 2017 in iot

Blink security cameras are an affordable home security camera system. Although they lack a formal public API, inventive devs have reverse-engineered their private API to allow for better integration.

Here we'll use AWS IOT Core, Lambda and node-blink-security to arm and disarm Blink security cameras using an AWS IOT Button.

Activating Your IOT Button

The IOT Button must be configured to your account, which includes joining it to your wifi access point, and installing the client certificates.

The easiest way to perform activation is by using the AWS IOT Button App for Android or IOS. Complete instructions are found on the AWS Docs

Creating Your Lambda function

You can re-use the AWS iot-button-email lambda template which will help you bind your lambda function to your own iot button. We will later modify the code with custom code to integrate blink.

Be sure to use the node-6 runtime

At this point you should be able to send test emails by clicking your IOT button.

Installing the Blink IOT Button Lambda Function

Although the lambda code is minimal, it requires node dependencies. The complete deploy package can be found at the iot-button-blink-alarm repo

Make sure to modify lambda/gulpfile.js to use the name of your lambda function.

$ export AWS_SECRET_ACCESS_KEY=xxxxxx AWS_ACCESS_KEY_ID=xxxxxx
$ cd lambda
$ yarn --prod
$ mkdir dist
$ cp -R index.js node_modules dist
$ yarn
$ yarn run deploy-lambda

At this point you can view your lambda function in the console to see the updated code & node_modules.

Obtaining a Blink Auth Token

Instead of storing your username and password on lambda, we'll obtain an auth-token and store it as an environment variable.

$ export BLINK_USERNAME=xxxxx BLINK_PASSWORD=xxxxx
$ bash curl/blink_login.sh
# {"authtoken":{"authtoken":"XXXXXOOOOOO","message":"auth"},"networks":{"100000":{"name":"TEST","onboarded":true}},"region":{"rest.prod":"United States"}

Now log into the lambda console & set these 3 environment variables according to the response from blink_login.sh

  • BLINK_AUTH_TOKEN=XXXXX0000000
  • BLINK_NETWORK_ID=100000
  • BLINK_REGION_ID=rest.prod

Testing the IOT Button

At this point the button should be set up to arm your system with a SINGLE click and disarm with a DOUBLE click. Test the button while watching the cloudwatch log stream to verify the success.

Testing Locally With Docker (optional)

To simplify the testing process, you can use docker with the lambci/lambda image to test locally before deploying.

$ docker run --env-file=.env -v "$PWD":/var/task lambci/lambda:nodejs6.10 \
index.handler '{"clickType":"DOUBLE"}'

Although there are quite a few steps, in the end you'll not only have a button you can use to arm your Blink security system, but you'll have learned all of the steps required to integrate any iot device into a custom lambda function.

This could be extended to manage switches, sensors and more.