Internet of things is a hot-buzz-word in the field of AI these days. However, the concept was developed about 20 years ago by @kevin_ashton. Let’s have a simple definition to get it introduced.
The network of small devices connected with sensors, which can communicate over the internet and are capable of sending/recieving data and trigger some action based on certain conditions.
There is a lot more in introduction itself like application areas, communication architecture, security and much more. I would suggest going through the IoT’s wiki.
I am going to show how to configure nodemcu with AWS with security certificates. I have selected nodemcu as IoT device and DHT11 temperature sensor, both are easily available online. The basic idea is to get notification using AWS serveless stack when the temperature hits too high. Now let’s configure the device and feed some code to it.
Setting Up The Device
To get started, you need to install
Ardruino IDE (download)
NodeMCU Driver (download CH340 or CP210x) check the name on nodemcu.
Step #1
Open arduino IDE preferences and update “Additional Boards Manager URLs” value with
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Step #2
Open Tools -> Boards -> Board Manager. Search for esp8266 and install it.
Now select Tools -> Boards -> NodeMCU 1.0(ESP-12E Module) and connect your device to USB port. Check if your device is working fine, or you are connected to the correct port by clicking on Tools -> Board Info. You will get a pop-up window(see image below).
If it throws an error, try changing port listed under Tool -> Port. If you are still getting error, then probably the driver is not installed properly.
Step #3
Search and install required libraries under Sketch -> Include Library -> Manage Libraries
DHT sensor library (by Adafruit)
PubSubClient (by Nick O’Leary)
Step #4
Now go to AWS IoT Core and create a policy. You will need this while creating the certificates. Replace aws account id, you can find it in your aws account settings.
Step #5
Create certificates and download them from Security -> Certificates using “One-click certificate creation”. Activate the certificate and attach the policy that you have created in the previous step.
To check the certs are in action. When you perform step #8 successfully, just deactivate the certificate and try reconnecting again. You will not be able to connect the until the certificate is activated.
Step #6
Coding Time! Replace the placeholders with your values. Use any text editor to open the downloaded certificatates.
Take a close look at the code and verify values that you have updated. Now compile and upload the code to your device.
Disconnect the device and connect the sensor to the following pins on the Nodemcu.
Connect + to 3v3 (Voltage Pin)
Connect - to GND (Ground Pin)
Connect out to D2 (Data Pin)
Step #8
Check the connections.
Reconnect your device via USB and open Tools -> Serial Monitor. You will see the output of the iot device here. Now, go to AWS IoT and on the main dashboard, click on “Test” in the sidebar menu. Enter device id and subscribe to it. At this point, you should start getting data on the AWS IoT.
If you encounter any error here, check the “Serial Monitor.” There might be connection issue with network or your temperature sensor may not send data to the IoT device.
So far, you are able to connect the IoT device to AWS cloud. Now we are good to go to part 2, which is focused on the backend that manages data from IoT device and notifications.