Cloud Home Automation Series: Part 1 Connect ESP32 to AWS IoT with Arduino code

Cloud Home Automation Series: Part 1 Connect ESP32 to AWS IoT with Arduino code

Welcome to SIMPLE LEARNING AWS Cloud Home Automation, Zero to Hero Series, where the readership, essentially Embedded System Engineer & Cloud Engineer will able to learn to create Automated IoT Solutions using ESP32 Module (Hardware), AWS IoT portfolio services (MQTT & Integration assistance) & Arduino sketch or code (Firmware). The entire series mainly focuses on the Hardware integration with AWS Cloud to make a system of interrelated computing devices.

Like all the AWS IOT apps and Alexa but first time my Alexa alarms failed when internet went Down I realized its not just lack of security but Resilence it lacks. i have to fix all the Smart home apps or create new ones to work in a smart home while its offline internet or grid power is down. Emergencies like last year in 2019 had our home systems paralized without internet. Added an old 555 timer for .25 cents is all it took for home to work on a battery Alarm,Alert and timer system in our Home of Things Fog network. AWS could still offer us IPFS archives and backup but will add a FOG server to my home as some AI needs to operate local for Security Systems and even cooking otherwise we burn the food or cause fires when internet drops out.

Hi Alan, I agree that power outage and internet connectivity are major roadblocks. I would suggest using AWS IoT Greengrass for local execution. For resiliency, you may have a second channel to interact with your devices either use The Things Network (global open LoRaWAN network) or LoRa modules.

Thanks gourav-das, your suggestions are most helpful. This should keep me busy this week. I also found a local company https://www.semtech.com/company/press/semtech-announces-open-source-software-for-lora-based-gateways-at-the-things-conference that makes an Open Source LoRa packet-forwarder.
I have a Buoy 3.6 mile offshore i need communication with will try this.

Hey gourav-das, great tutorial. Was able to follow part 1 together with the bonus lesson. However I ran into one problem. After uploading the code I get an error message Error (-28) connecting to the AWS endpoint via port 8883 … trying to reconnect.

When I go to the AWS console / Settings the custom endpoint says ‘ENABLED’ in green (top right) so not sure what’s going on.

Also why do you publish random values and not the actual temp from the sensor?

Thanks Thomas for reading and great job for following all the steps :slight_smile: .

  1. Your error seems like there is some issue with your policy. Try to replicate the same policy as shown below, go to IoT Core Main Dashboard , In Side Bar Select Secure --> Polices -->The policy you created for this exercise.
    image

  2. As I want to keep the implementation minimalistic thus I haven’t integrated it with DHT module. If you are interested to add a DHT module to this project, I uploaded the code which receives data from DHT module, [click here] to download the ino file.

If you are still facing the same issue , let’s connect on LinkedIn.

Thanks for the quick response.

(1) The policy looks as per your extract although iot:Connect and iot:Publish were in the other order - changing of which didn’t have any impact.

What I don’t understand is the message in the console “Trying to reconnect” doesn’t seem to come from the sketch. If the connection is not successful I would expect the message “AWS connection failed, Check the HOST Address”

if(hornbill.connect(HOST_ADDRESS,CLIENT_ID)== 0) // Connect to AWS using Host Address and Client ID
{
Serial.println(“Connected to AWS”);
delay(1000);
}
else
{
Serial.println(“AWS connection failed, Check the HOST Address”);
while(1);
}
}

Instead what I get is …

Connected to WiFi
192.168.2.168
E (25565) AWS_IOT: Error(-28) connecting to axxxxxxxxmvady-ats.iot.us-east-1.amazonaws.com:8883,

Trying to reconnect

  1. The DHT module needs the DHT library. Where can I find that?

Hi Thomas,
As discussed, by activating the Certificate, it has started working.
Thanks for your valuable feedback. I have updated all my documents so that there is no room for error.

Also I forgot to mention you need DHT libraries to make your DHT sensor working. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
Search for “DHT” on the Search box and install the DHT library from Adafruit.