Introduction: Getting Started With Amazon AWS IoT and ESP8266

This project shows you how to take the ESP8266 module and connect it directly to AWS IOT using Mongoose OS. Mongoose OS is an open source operating system for microcontrollers that emphasizes cloud connectivity. It was developed by Cesanta, a Dublin-based embedded software company and at the end of the project, you should be able to measure the temperature and the humidity values from the DHT11 temperature sensor and publish it on the AWS IOT platform

For this project, we’ll need:

 An ESP8266-based NodeMCU board

 DHT 11 temperature sensor

 The Mongoose OS flashing tool

 A USB cable to connect the NodeMCU board to computer

 Jumber wires

 AWS account that you intend to use

Step 1: An ESP8266-based NodeMCU Board

The ESP8266 is the name of a micro controller designed by Espressif Systems. The ESP8266 itself is a self-contained Wi Fi networking solution offering as a bridge from existing micro controller to Wi Fi and is also capable of running self-contained applications. This module comes with a built in USB connector and a rich assortment of pin-outs. With a micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any trouble, just like Arduino

Specification

• Voltage: 3.3V.

• Wi-Fi Direct (P2P), soft-AP.

• Current consumption: 10uA~170mA.

• Flash memory attachable: 16MB max (512K normal).

• Integrated TCP/IP protocol stack.

• Processor: Tensilica L106 32-bit.

• Processor speed: 80~160MHz.

• RAM: 32K + 80K.

• GPIOs: 17 (multiplexed with other functions).

• Analog to Digital: 1 input with 1024 step resolution.

• +19.5dBm output power in 802.11b mode

• 802.11 support: b/g/n.

• Maximum concurrent TCP connections: 5

Step 2: Pin Diagram

Step 3: DHT11 - Humidity and Temperature Sensor

The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).It’s fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds

Features

 Full range temperature compensated

 Relative humidity and temperature measurement

 Calibrated digital signal

 Outstanding long-term stability

 Extra components not needed

 Long transmission distance

 Low power consumption

Communication Process (Single-Wire Two-Way)

The interesting thing in this module is the protocol that uses to transfer data. All the sensor readings are sent using a single wire bus which reduces the cost and extends the distance. In order to send data over a bus you have to describe the way the data will be transferred, so that transmitter and receiver can understand what says each other. This is what a protocol does. It describes the way the data are transmitted. On DHT-11 the 1-wire data bus is pulled up with a resistor to VCC. So if nothing is occurred the voltage on the bus is equal to VCC.
Communication Format can be separated into three stages

1) Request

2) Response

3) Data Reading

Step 4: Introduction to Mongoose OS

Mongoose OS is an open-source operating system for tiny embedded systems. It is designed to run on devices such as micro controllers, which are often constrained with memory on the order of tens of kilobytes, while exposing a programming interface that provides access to modern APIs normally found on more powerful devices. A device running Mongoose OS has access to operating system functionality such as file systems and networking, plus higher-level software such as a JavaScript engine and cloud access APIs.

Mongoose OS Flashing tool

Flashing tool is used to flash the Mongoose OS in ESP8266 .First, get one of the supported boards, like the ESP8266 NodeMCU, and connect it to your computer, then follow these steps:

 Navigate to the Mongoose OS download web page and download the Mos tool. (But in this Project, we are going to use the older version of Mongoose OS)

 Run the Mos (Mongoose OS) setup file and follow the setup wizard:

Step 5: The Mongoose Setup Wizard

Step 6: Device Status - Online

After completing the three steps, you will get the message in given below and the Device status becomes online. Now our ESP8266 Module is able to communicate with any remote devices

Step 7: Provision Device on AWS IOT

Before we can send events to AWS we need to be able to make a secure connection to AWS IOT. In order to do so we need to provision the ESP with the AWS certificates. In the Mongoose OS setup wizard choose the Device Config menu then Choose the appropriate AWS region and the AWS policy for your AWS environment. Click the Provision with AWS IOT button. The device will be set-up with the correct information to connect to the AWS service. The certificates will be installed automatically.

Note:

User can select the appropriate AWS region and AWS policy.In our scenario,we selected AWS region as ap-southeast-1 and AWS policy as mos-default


After the completion of the provision device on AWS IOT, now the esp8266 Wi-Fi module can be able to communicate with AWS -IOT

Step 8: Loading the Sample Code Into NodeMCU Board

After you run the Mongoose setup wizard, if you click the device files menu, there is a file called init.js.Inside that file there is sample code .If you click the Save +Reboot button, the sample code will be loaded and the output can be viewed from the Device Logs

Step 9: Getting Started With AWS Account

What is AWS?

Amazon Web Services (AWS) is a cloud service provider from Amazon, which provides services in the form of building blocks, these building blocks can be used to create and deploy any type of application in the cloud. These services or building blocks are designed to work with each other, and result in applications which are sophisticated and highly scalable.

How to setup?

There are two ways to set up AWS services

 Using AWS CLI command line utility

 Using AWS GUI

Step 10: ​AWS CLI Command Line Utility (Optional)

First we need to install AWS CLI. AWS CLI is a command line tool that provides commands for interacting with AWS services. It enables you to use the functionality provided by the AWS Management Console from the terminal. Mongoose uses this tool to Provision the IOT device on AWS IOT. The AWS CLI needs your credentials to be able to connect to AWS. To setup run aws configure from the command line and enter your access information(your credentials). In simple words, you can access and manage Amazon Web Services through a simple and intuitive web-based user interface. If your concern is accessing some of the features using mobile phone, then AWS Console mobile app lets you quickly view resources on the go.

Step 11: Amazon Web Services ( GUI )

After provision with AWS, we can log into the AWS management console, under the services tab we have different categories. Before we start exploring the features of this console, you need to create an account on AWS. For people who do not have an account can visit AWS website and create a free account. You must enter your credit/debit card details. AWS would not charge you during your free subscription as long as you use the services as per the specified limits.

Step 12: AWS IOT Core

After the log in, you will be directed to the following page and under the Internet of things select the IOT core

Step 13: AWS IOT - Monitor

Once you select the IOT core the above page will appear then select the test menu

Step 14: AWS IOT - Subscriptions

After selecting the Test menu you will be directed to Subscriptions .In the subscription topic specify the appropriate topic that you are using and click the Subscribe to topic button

Step 15: Publishing the Default Message

After that you will be directed to the above page. If you click Publish to topic, we will have the sample message which will be displayed here by default

Note:
If you want to write a new code and load into NodeMCU board (The code that we write should be loaded in the device file manager > init.js file then you should include the topic name in the code. After including the topic name, you have to use the same topic name in the subscriptions section in order to be publish the output

Step 16: Publishing the Button Pressed Information

Step 17: Publish the Temperature and Humidity Values to the AWS IOT Platform

Step 18: ​Task

Connect the circuit as shown below

 Flash the mongoose OS on the ESP8266 module

 Provision device on AWS IOT

 Load the programming code into the NodeMCU board

 Check the output in the device logs (see figure 9)

 Log into the AWS account

 Select the IOT core sub menu

 Select the Test option from the MQTT client section

 Specify the appropriate topic in the subscriptions

 Click the publish to topic button

 Make sure that whenever you press the flash button you are getting the temperature, humidity values as messages

Step 19: Circuit Diagram

Step 20: The Programming Code

Step 21: Mos Setup File