Pushing sensor data onto AWS from scratch in 15 minutes

Alex JonssonBlogs, Tutorials

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+

In this exciting tutorial, you’ll learn how to create a mobile app in JavaScript using Evothings Studio, that sends data from a sensor device to the cloud and back home using Amazon’s AWS Lambda and DynamoDB.

By clever use of scripts and dynamic web tools, both for configuring the cloud services and for hooking up a Bluetooth-enabled sensor, live data is sent cloudside using your phone as a gateway, and back again from the cloud to show the result, and you easily control any aspect of how it looks and works – all the action here is created using HTML5 and JavaScript.

So before you start your kitchen egg timer just to challenge the article’s headline, you’d want to have an AWS account setup handy with username/password – any free or or paid account doesn’t matter. And this set-up is just an example, even if it’s a pretty cool one.

Our demo app continously reads temperature data from a Texas Instruments SensorTag [ti.com/sensortag] Bluetooth enabled device and passes the data to AWS using a phone as a gateway. If you don’t have access to a SensorTag you can still stay with the action; you can use the demo app for reading and writing simulated sensor data instead, and just add a physical device of your own later on. In addition, you could experiment using some other brand of BLE-enabled sensor, though I’ll willingly admit that going rogue with other device models will require some additional programming, and this tutorial is bespoke for the Bluetooth SimpleLink SensorTags provided by Texas Instruments, with the extreme short time limit in mind. So here we go, game on!

Setting up AWS (estimate time for this step; 5 min)

On AWS, we’re using three services;
– A Lambda service which is an event listener for aggregating data,
– the Dynamo database for storage where you can make queries later on,
– IAM to set up a role on AWS with very limited capabilities, and safer to use than your root account; you won’t need to flash the identity or credentials around for your personal or your company’s main Amazon account.

Start by following this cloud-side wizard [ amzn.to/1cVzMZN ] in your computer’s web browser to set up your AWS services (i.e. IAM to create a designated user role, Lambda to run code on incoming events and DynamoDB to store and retrieve data). Most fields and checkboxes are pre-configured. In practice that means that you need to press “next” and “ok” on the screens to follow, as the fields are filled in already with what you need, thanks to the scripted wizard in the link provided.

Many AWS services, like Lambda and DynamoDB are available for limited use without cost in the Free tier. Follow this link for the details on creating yoru free account, or use the account you have: aws.amazon.com/free/. To be precise, the free AWS tier has in our case the following limits (Sept 2016):
Amazon DynamoDB: 25 GB of Storage, 25 Units of Read Capacity and 25 Units of Write Capacity, up to 200M requests per month. For
Amazon Lambda service: 1,000,000 free requests, and 3.2 million seconds of compute time per month.

1. Selecting a Template.
The wizard helps you define a software stack (called an “AWS CloudFormation” in Amazon lingo), which is a collection of resources you’ll need. The default stack name is “IOT2015”, which was for last year when our friends at Amazon set up this script for us originally. There is also a preconfigured AWS S3 template you’ll find called “ioe2015.s3.amazonaws.com/iot.template” which automates most of the setup. In this screen, you can download the template’s script if you want to see what it does in details. On this screen you don’t need to alter anything really.

Press Next.

Screen Shot 2015-09-09 at 17.19.16

2. Specify Parameters, this is where the Lambda function’s parameters are defined. (Basically, the AWS Lambda is a simple yet efficient event listener and queuing mechanism which is used for gathering sensor data.) Use the default bucket name “ioe2015” and the Lambda package S3 key “iotapi.zip”.

Press Next.

Screen Shot 2015-09-09 at 17.19.25

This is the Options screen. You can leave the fields blank.

Press Next.

Screen Shot 2015-09-09 at 17.19.33

3. Review screen This screen summarises what will be going on, once you execute your setup;

  1. Creation of the Lambda function for triggering code on incoming events
  2. A DynamoDB database table for storing values
  3. A new user in the IAM service (Identity and Access Management), with access only to (1) and (2), and not anything else you’re running on AWS.

Check the checkbox to allow creation of the user and permissions.

Press Create.

Now the service setup on AWS is complete. You don’t have to create additional Stacks or Services, even if the landing screen arguably tempts you to do so.

When the CloudFormation stack creation is complete, just wait for it a number of seconds – select the created IOE2015 stack and click the Outputs tab. There you can see the configuration values that you should enter in the configuration of the Evothings application. Have these values ready to enter in the steps below. If you do mess up, don’t fret, you can always go to CloudFormation from the main menu, and click Outut from there.


You’ve now all done with Amazon AWS set up and are good to go for the next step, hang on, we’re going mobile!

Evothings Studio (2:30 min)

Download and install the Evothings Studio workbench software from [evothings.com/download] and the corresponding Evothings Viewer app to your iPhone or Android least to type by searching for “evothings” via the public app stores. The Alpha release of Evothings Studio 2.0 will also work fine. The Evothings Client app (Evothings Viewer app if you’re using the 2.0 Alpha) will help you to preview your app in realtime while developing it, without compiling each time.

Connect your phone to the workbench by generating a connect code on the computer, a short string of letters and numbers, to punch it into the Evothings Viewer to pair your phone with Evothings Studio, and run the Hello World from the Workbench window just for good measure.

The AWS-IoT project app (2:30 min)

Download the EvoAWS example project [bit.ly/EvoAWS] and unzip it. Open the “aws-config.js” file and enter your AWS credentials for the IOT2015 user, for example (you need to make you own keys though):

evothings.aws.config =
{ //generate access keys under IAM
secretAccessKey: 'asdASDFOIasdfopadsfpoiadfSOIadsfAPODSFi23423',

// find FunctionName and region under Lambda
region: 'eu-west-1',
params: { FunctionName: 'IOE2015-IoTAPI-XXFLIHSDLFHLDF'}

Press Save.

Drag-n-drop the main index.html file into the Evothings Studio workbench window and press run. The app now loads at once on your phone.

Test operations by pressing the top button READ/WRITE DEMO in the app. Write some random data by pressing WRITE TEMPERATURE VALUE. Now read the data just written by pressing READ TEMPERATURE VALUE. This shows that your AWS Lambda service is working correctly.

Navigate back to the app main menu and select the third menu option on-screen, the SENSORTAG DEMO example.

Connect the TI SensorTag (30 seconds)

The TI SensorTag has a pushbutton on the side, and long pressing it sets the device in announcement mode, whereby a tiny green light flashes continuously. Press button START READING SENSORTAG in the app, and after a few seconds the data will flow!

But wait, I look again at my egg timer, and this is only a grand total of ten and a half minutes… Well, I know and there is a plan for this case; we suggest you use our remaining 270 seconds to go ahead and modify the “index.html” file. Every time you press save, all changes you’ve made will reflect automagically on your connected client app. Or why not alter the behaviour by changing the temperatureInterval value to 5000 (ms) on line 64 in the file aws-app-sensortag.html. Press save, and you’ll see temperature data coming in more frequently, without recompilng, re-signing or waiting!

The tutorial is over, but the challenge remains like they’d say in a cheesy Hong Kong movie. It’s your app now, so feel free to change pretty much any aspect of it you’d like using your HTML5 and JavaScript skills, no compiling, no signing, no waiting either, just like developing IoT service should be! Why not add some steampunk analog gauges from the Google Charts arsenal like in another tutorial we published last Summer.

If you’ve read all the way to here without hacking, then you really should get to it, and try it out – it’s fun and easy to create mobile IoT services, once you know how it’s done. Don’t forget to drop by the forum to show off what you’ve created,, reach out and share code and thoughts, or ask questions to a growing developer community around cloud, mobile, IoT and web technologies.

More on AWS and how to get started: aws.amazon.com/
AWS programme for startups: aws.amazon.com/activate/
AWS Free Tier: aws.amazon.com/free/

More tutorials and useful code for your mobile IoT needs at evothings.com/developer


Eddystone is coming, opening up the beacon space

Estimote, Kontakt and Radius Networks are upping their hardware offerings, here’s some things you need to know.
Read more→


Evothings Studio is coming cloud-side

Going from a downloadable product into a Saas solution, brings on a wide array of new possibilities. Join the growing community and learn more about the benefits of moving from desktop onto the cloud for mobile development.
Read more and download→


Ready for app stores with Phonegap Build

A simple way to build and sign your app for publishing, is via a build service. Adobe’s Phongegap Build is one for the candidates.
Read more→