Hexiwear goes cloudside on Amazon AWS

Alex JonssonUncategorized

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

awsThis is a step-by-step tutorial for publishing Hexiwear sensor data onto the Amazon cloud. You’ll need (1) an Amazon AWS account, a PC, Mac or Linux computer, (2) a smartphone with Bluetooth turned on and (3) a Hexiwear device to pass the finish line. Traditionally, it sure takes a while to set up the server-side of this project, while in this case we’ve prepared an AWS script for doing most of the heavy lifting for us.

We’ll be using three AWS 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.

If you don’t have access to a physical Hexiwear device yet, or have just ordered one, you can still stay with the action; you can use the demo app for reading and writing simulated sensor data, and add a physical device to the setup later on.

Update Wednesday October 26, 2016: The example app enclosed has been updated, specifically its pairing and bonding capabilities are now stable on both iOS and Andriod!

The mobile device will be acting as a gateway for the Hexiwear, passing on the sensor data to the cloud. In coming tutorials, we’ll also be showing how a smartphone or tablet can be used as a remote to dynamically control which sensor data is sent, and how to easily set different modes on the Hexiwear, using it as a peripheral device. We’ll also investigate how data can be visualised on the mobile device using javascript libraries like the Smoothie.js chart library, Google Charts and Three.js.

Setting up AWS, in a rapid Evothings style

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 thre 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

Download and install the Evothings Studio software and the corresponding Evothings Viewer app to your iPhone or Android – search for “evothings viewer” via the public app stores. While you’re on the Evothings Download page, you can also generate a Cloud Token which you’ll be asked to paste in Evothings Studio when you connect the first time. It’s an anonymous serial number, which allows you to see which computer is connected to which phone(s) when you run the Evothings Studio software. It will looks something like this:

Lastly, connect your phone to your computer by generating a connect code on the computer by pressing the GET KEY button. A short string of letters and numbers appears, for you to type into the Evothings Viewer. Go to Examples and run .e.g. the Hello World to see an app load on your mobile device.

The Hexiwear AWS example

Download the example project and unzip it in a directory with write permissions. You can find it here: evothings.com/hexiwear/hexiwear-sensors-aws.zip

Open the file called “aws-config.js” file and enter your AWS credentials for the IOT2015 user, that you found under the Output tab in CloudFormation previously.

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 and drop the main index.html file into the Evothings Studio workbench window and press RUN. The app now loads at once on your smartphone. 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. This is the point in time where the Hexiwear actually comes into play, at last some hardware in action:

Connecting the Hexiwear

Perhaps you’ve already played around with the Hexiwear and your smartphone. Then you’ve already paired the Hexiwear device with your phone, otherwise you’ll get an on-screen six-digit number shown on the Hexiwear’s 96×96 pixel display, to enter on your mobile device when you RUN your Evothings app for the first time. The Hexiwear device has several modes, so set the Hexiwear either as a Beacon (main menu) or as a Pedometer as the sensors will become active in these modes. Press Connect in the mobile app on your smartphone or tablet, and see the status message changing from scanning to uploading data. Just like clockwork! You’re done and have now completed this tutorial with flying colors.

The code source and open source licensing

The source code for this app is released under an open source Apache2 licence, so you can play around, share, modify, publish or sell the code as you desire. Perhaps you’d like to see some steampunk analog gauges from the Google Charts arsenal like the ones we published previously in another tutorial. You’ll need to do more of your own tinkering then, if we get lots of followers on this one, we might just do it for you.

Links, further reading

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