Over a million developers have joined DZone.

Getting Started With AWS IoT and Tessel

DZone 's Guide to

Getting Started With AWS IoT and Tessel

Get started with AWS IoT by Tessel, which is an IoT device running Node.js See a simple example of how to set up and configure a device.

· IoT Zone ·
Free Resource

AWS launched its IoT service at re:Invent 2015 and made it available for everyone in December 2015. I’ll show you how to get started with AWS IoT by using a thing, called Tessel, connected to the Internet during this article.

Connecting AWS IoT and Tessel

What is AWS IoT?

AWS IoT allows you to build an IoT infrastructure and integrate with many other AWS services. Combine the following components of AWS IoT as needed to cover your requirements.

  • Device Gateway: Enables things to communicate with AWS IoT.
  • Message Broker: Provides a pub-sub system based on MQTT, WebSocket, or HTTP REST pub.
  • Rules Engine: Routes messages to integrated services like S3, DynamoDB, and Lambda based on conditions.
  • Security and Identity: Manages identity and access credentials for your things.
  • Thing Registry: Organizes devices helping you to keep an overview of your fleet.
  • Thing Shadow: Synchronizes device state between the device and the backend service.

AWS IoT is a fully managed service, which means AWS is subject for operating the service with high availability and scalability.

What Is Tessel?

A Tessel is an IoT device running JavaScript, or more precisely Node.js. The latest version, Tessel 2, is providing connectivity over Ethernet and Wi-Fi and is offering two module ports and two USB ports.

My Tessel 2

There are a bunch of modules available that can be attached the module and USB ports:

  • Accelerometer: Detect orientation and movement.
  • Ambient: Meters sound and light intensity.
  • Relay: Switches power.
  • Climate: Meters temperature and humidity.
  • Infrared: Sends and detects infrared signals.
  • Servo: Controls a servo.
  • RFID: Reads RFID cards.
  • GPS: Detects global position.
  • Bluetooth LE: Communicates via Bluetooth Low Energie.
  • Cellular: Communicates via 3G.
  • Camera: Takes pictures and records video.
  • Audio: Records audio.
  • Various community-created modules for even more flexibility and fun!

As you will see next, combining AWS IoT and a Tessel provides a flexible and easy-to-use IoT development environment. An excellent basis for a prototype or proof-of-concept.

Simple Example: Temperature Alert

The following example guides you through setting up a temperature alert with Tessel and AWS IoT. The climate module is used to meter the temperature. The device will report a measuring point every minute. The following figure illustrates the setup.

Setup of IoT example

Configure the IoT infrastructure by following these steps:

  1. Log in to the AWS Management Console, select region N. Virginia, and switch to AWS IoT.
  2. Click on Create a Resource and select Create a Thing.
  3. Choose temperature-sensor as Name and click on Create.
  4. Select the newly created thing temperature-sensor and click on Connect a device.
  5. Select Node.js from the list of SDKs and click on Generate certificate and policy.
  6. Download the public key, the private key, and the certificate and click on Confirm and start connecting.
  7. Copy the shown configuration (JSON) and click on Return to Thing Detail.

Deploying your temperature collector to Tessel by following these steps:

  1. Connect to your Tessel by following Tessel Start.
  2. Create a project directory.
  3. Connect the climate module to port A of your Tessel.
  4. Download the root certificate.
  5. Move the downloaded private key, certificate, and root certificate to the directory.
  6. Rename the private key to private.pem.key.
  7. Rename the certificate to certificate.pem.crt.
  8. Rename the root certificate to root-certificate.pem.crt.
  9. Copy the source code from below to a file named index.js.
  10. Copy the content from below to a file named .tesselinclude.
  11. Run t2 push index.js from your command line. Make sure setting your current working directory to the project directory.

Content of Index.js

var iot = require('aws-iot-device-sdk');
var tessel = require('tessel');
var climatelib = require('climate-si7020');

var climate = climatelib.use(tessel.port['A']);

var device = iot.device({
  keyPath: __dirname + '/private.pem.key',
  certPath: __dirname + '/certificate.pem.crt',
  caPath: __dirname + '/root-certificate.pem.crt',
  clientId: 'temperature-sensor',
  region: 'us-east-1'

climate.on('ready', function () {
  setInterval( function () {
    climate.readTemperature('c', function (err, temperature) {
      if (err) {
        throw err;
      } else {
          console.log(`publish temperature: ${temperature}`);
        device.publish('temperature', JSON.stringify({temperature: temperature}));
  }, 60000);

device.on('connect', function() {

device.on('close', function() {

device.on('reconnect', function() {

device.on('error', function(err) {

device.on('offline', function() {

Content of .Tesselinclude


Your Tessel is now sending temperature measuring points to AWS IoT every minute. You deserve a short break.

There is only one thing missing: Setting up an alert if the temperature increases a threshold value.

First of all, you need to setup an SNS topic and subscribe to messages via email:

  1. Log into the AWS Management Console, select region N. Virginia, and switch to AWS SNS.
  2. Select Topics from the sub-navigation.
  3. Click on Create new topic.
  4. Enter temperature-alert as Topic name and click on Create topic.
  5. Open the details of the created topic by clicking on its ARN.
  6. Click on Create subscription.
  7. Select Email as Protocol and insert your email address into Endpoint.
  8. Wait for an incoming mail from SNS and confirm the subscription by clicking on the provided link.

Everything is ready to create a rule containing a condition to trigger an alert if the temperature exceeds the defined threshold. Follow these steps to setup an IoT rule:

  1. Log in to the AWS Management Console, select region N. Virginia, and switch to AWS IoT.
  2. Click on Create a Resource and select Create a Rule.
  3. Choose temperaturealert as Name.
  4. Fill in temperature as Attribute and Topic filter.
  5. Insert temperature > 10 as condition.
  6. Select `Send message as a push notification (SNS) at Choose an action*.
  7. Select `temperature-alert at SNS target*.
  8. Fill in RAW as Message format.
  9. Click on Create a new role to create a new IAM role allowing the IoT rule to send messages to SNS.
  10. Type in temperature-alert as name and click on Create.
  11. Click on Add action.
  12. Click on Create to create the IoT rule.

You will receive an email whenever a temperature measurement point exceeds 10 degree Celsius. Adopt the condition in the IoT rule if you want to get alerted at another threshold value.

Time to clean up! Follow these instructions to delete all created resources:

  1. Log into the AWS Management Console, select region N. Virginia, and switch to AWS SNS.
  2. Select Topics from the sub navigation.
  3. Pick the element named temperature-alert and click on Actions and choose Delete topics.
  4. Switch to AWS IoT.
  5. Delete the IoT rule temperature.
  6. Deactivate the certificate and detach it from the policy and the thing.
  7. Delete the certificate.
  8. Delete the policy temperature-sensor-Policy and the thing temperature-sensor.

Congratulations! You have successfully deployed your first IoT application on AWS.

Benefits of using AWS IoT

I’d like to highlight the benefits of using AWS IoT as a conclusion. The main advantages of using AWS IoT from my experience are:

  • Write less code: Implementing IoT applications is possible almost without any code at all
  • Serverless Infrastructure: Focus on building your IoT applications instead of investing into setting up the infrastructure
  • Integrate all the things: AWS IoT integrates into the AWS service portfolio including S3, DynamoDB, SNS, Lambda, and much more
  • Simplify Deployment: Use the CLI, SDKs or CloudFormation to deploy your IoT applications in an automated way

Watch out our blogs for more content about AWS IoT shortly!

aws iot ,development ,services ,iot application ,environment ,application ,infrastructure ,service ,aws

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}