Table of Contents:
Overview:
In this tutorial, I will tell you how you can do Temperature Data record on AWS IoT Core with NodeMCU-ESP32 using Arduino IDE and MQTT Protocol.
Internet of Things (IoT) is being integrated with almost every device nowadays. There is a number of hardware and software IoT platforms are available in the market for building IoT based application. In my previous video, I have explained how to interface DHT22 with NodeMCU and post the Temperature and Humidity to the Thingspeak webserver. Likewise, we can interface sensors to the hardware development kits like ESP32, ESP8266, Raspberry Pi, Particleboards( Aargon, Boron, Xenon) and post data to the clouds like Thingspeak, Ubidots, AWS IoT Core, Microsoft Azure.
Amazon is not only in e-commerce but also focusing on IoT and providing cloud-based service named as AWS IoT. Here, AWS IOT stands for Amazon Web Service Internet of Things. This service allows us to connect our devices to the internet for processing, operating and exchanging data securely. Along with AWS IoT, the Amazon Web Services also provides tons of other features like virtual machine deployment, web-hosting, etc.
Requirements for this Tutorial :
- ESP32 Buy from Amazon
- DHT11/22 Buy from Amazon
- Data Cable Buy from Amazon
- An active account on Amazon Web Services(AWS).
- Arduino IDE installed on your computer with ESP32 board configured.
Steps involved in this tutorial:
- Installing Required Libraries
- Creating Thing in the AWS, generating a certificate and attaching a policy to it.
- Modifications in the Arduino sketch according to the thing.
- Testing/Subscription of thing on Amazon Web Services(AWS).
- Uploading code to the ESP32 & Live demo of Data Logging.
Let’s begin the journey:
Check the links given below and download the libraries from the GitHub.
GitHub links Libraries:
Hornbill-Examples – https://github.com/ExploreEmbedded/Hornbill-Examples
DHT Sensor Library – https://github.com/adafruit/DHT-sensor-library
Tutorial Video:
You can watch the following video to knew how you can do Temperature Data record on AWS IoT Core with NodeMCU-ESP32 using Arduino IDE and MQTT Protocol.
It will be a little bit difficult for me to explain everything here. I suggest you follow the video. I will provide the rest of the necessary information like source code and circuit diagram below the video.
Circuit Diagram:
Source Code:
/* Developed by M V Subrahmanyam - https://www.linkedin.com/in/veera-subrahmanyam-mediboina-b63997145/ Project: AWS | NodeMCU ESP32 Tutorials Electronics Innovation - www.electronicsinnovation.com GitHub - https://github.com/VeeruSubbuAmi YouTube - http://bit.ly/Electronics_Innovation Upload date: 28 July 2019 AWS Iot Core DHT Sensor Library - https://github.com/adafruit/DHT-sensor-library Hornbill-Examples - https://github.com/ExploreEmbedded/Hornbill-Examples AWS - https://aws.amazon.com/ In this script will help you to Read temperature and humidity from DHT11 and publishes that data to AWS using MQTT Protocol. Note: 1)Connect VCC to 3.3V, GND to GND and DATA pin to pin specified in #define DHT_PIN of DHT11 2) If you wanted to work with DHT22 you can use the same script by changing #define DHT_TYPE DHT22 2)In this sketch Hornbill-Examples library is used for the handling of publishing data via MQTT Hornbill-Examples uses aws-iot-device-sdk-embedded-C library provided by AWS to interact with AWS. Use aws-iot-device-sdk-embedded-C library for creating your own code for handling transfer. Link for aws-iot-device-sdk-embedded-C is given above. 3)DHT-sensor-library is used for reading data from DHT11 All the Links are given above. */ #include<WiFi.h>; #include<DHT.h>; #include<AWS_IOT.h>; #define DHT_PIN 33 // pin connected to data pin of DHT11 #define DHT_TYPE DHT11 // Type of the DHT Sensor, DHT11/DHT22 #define WIFI_SSID "Electronics Innovation" // SSID of your WIFI #define WIFI_PASSWD "subscribe" //your wifi password #define CLIENT_ID "Temp_Humidity"// thing unique ID, this id should be unique among all things associated with your AWS account. #define MQTT_TOPIC "Your MQTT topic" //topic for the MQTT data #define AWS_HOST "YOur aws host id, get this id by following the video" // your host for uploading data to AWS DHT dht(DHT_PIN, DHT_TYPE); AWS_IOT aws; void setup(){ Serial.begin(9600); Serial.print("\nInitializing thing Temp_Humidity_DHT11_0 \n"); Serial.print("\n Initializing WIFI: Connecting to "); Serial.println(WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWD); Serial.print(" "); while(WiFi.status() != WL_CONNECTED){ Serial.print("."); delay(500); } Serial.println("\n Connected.\n Done"); Serial.print("\n Initializing DHT11..."); dht.begin(); Serial.println(" Done."); Serial.println("\n Initializing connetction to AWS...."); if(aws.connect(AWS_HOST, CLIENT_ID) == 0){ // connects to host and returns 0 upon success Serial.println(" Connected to AWS\n Done."); } else { Serial.println(" Connection failed!\n make sure your subscription to MQTT in the test page"); } Serial.println(" Done.\n\nDone.\n"); } void loop(){ // read temperature and humidity float temp = dht.readTemperature(); // return temperature in °C float humidity = dht.readHumidity();// return humidity in % // check whether reading was successful or not if(temp == NAN || humidity == NAN){ // NAN means no available data Serial.println("Reading failed."); } else{ //create string payload for publishing String temp_humidity = "Temperature: "; temp_humidity += String(temp); temp_humidity += "°C Humidity: "; temp_humidity += String(humidity); temp_humidity += " %"; char payload[40]; temp_humidity.toCharArray(payload, 40); Serial.println("Publishing:- "); Serial.println(payload); if(aws.publish(MQTT_TOPIC, payload) == 0){// publishes payload and returns 0 upon success Serial.println("Success\n"); } else{ Serial.println("Failed!\n"); } } delay(1000); }
Final Output:
Serial Monitor data:
AWS Cloud data:
Thank you.
[…] You can check out the following link to connect your ESP32 with Amazon Web Services(AWS) […]
[…] have also made a tutorial on Temperature Data record on AWS IoT Core with NodeMCU-ESP32 using Arduino IDE and MQTT Protocol. This is Purely based on […]
[…] I have also made a tutorial on Temperature Data record on AWS IoT Core with NodeMCU-ESP32 using Arduino IDE and MQTT Protocol. […]
In my test the following error appears:
E (16108) aws_iot: failed! mbedtls_net_connect returned -0x52
E (16109) AWS_IOT: Error(-23) connecting to axepcgaprpv2k-ats.iot.us-west-2.amazonaws.com:8883,
HI Friend.. the tutorial is awesome.. i am facing this issue :
E (49073) AWS_IOT: Error(-28) connecting to a25vpyjbh9dgc1-ats.iot.us-west-2.amazonaws.com:8883,
please help me to solve. aws is not connecting
Hey man did you managed to find a solution?
hi thanks for the tutorial, im getting this error pls help me solve this “mbedtls/config.h: No such file or directory”.
hi, thanks, its excelent,
please, tell as how “see” de data like a dashboard for a client?
thanks
[…] I have also made a tutorial on Temperature Data record on AWS IoT Core with NodeMCU-ESP32 using Arduino IDE and MQTT Protocol. […]