Introduction: How to Send Data to Microsoft Azure IoT Central Using NodeMCU

IoT being an integral part of cloud computing, several cloud vendors make IoT part of the services they render. Also, with the emergence of IoT, there are different platform that makes IoT implementation available even to individuals. In this tutorial, I will be taking you through steps in sending data from NodeMCU, an IoT development platform to Azure IoT Central.

To ensure all necessary things are in place, you will have to set up your computer to communicate with NodeMCU or ESP8266 before you can follow along this tutorial.

In this tutorial, we will be using DHT 11 sensor to send Temperature and Humidity data to Azure IoT Central. 

Supplies

Materials Needed

1.      NodeMCU or ESP8266

2.      DHT 11 sensor

3.      10K resistor

4.      Personal Computer

5.      Arduino IDE software

6.      Jumper Wires

Step 1:

The very first step is to ensure that your PC has been configured to communicate with ESP 8266. If you haven’t done this already, now is the time. Once you have configured your PC, come right back to continue following this tutorial.

Step 2:

Hardware Setup: Connect the NodeMCU and the DHT 11 to the breadboard, depending on your model of DHT 11, it can be a 3-pin ready-made model or a 4-pin model, in this tutorial, I am using a 3-pin model. If you are using a 3-pin model, connect the VCC to 3V of the NodeMCU, GND of the DHT 11 to GND on the NodeMCU, and connect the data pin to Pin 4 of the NodeMCU. If it is the 4-pin model you are using, connect Pin 1 of the DHT11 to 3V of the NodeMCU, connect the 10K resistor between pin 1 and pin 2 of the DHT 11, leave pin 3 of the DHT 11 sensor unconnected, and connect pin 4 of the DHT 11 to GND on the NodeMCU. Connect the NodeMCU via a USB cable to your computer and you are good to go.


You will need to install the Adaruit DHT library to use read from the DHT sensor

Step 3:

Before writing the code, now is the time to set up the Azure cloud platform. First, sign in to your Azure portal. We will be working on IoT central. What you want to do is to use the search bar to search for IoT Central applications, click on IoT Central applications. Here you will click on create a new IoT Central application. At the prompts, fill in your application details, under the template section, select custom application. Once you are done filling in the details, click on create after which you can click on the go-to resource. Once the IoT application resource opens us, click on the application URL, this will take you to another tab where you will be able to work on the IoT applications. Everything we need to do to communicate between our IoT device and the cloud will be done in this tab. If you check the sidebar, you will see options like “Devices”, “Dashboard”, “Device Template”, etc.

Step 4:

Let me walk you through our main aim on this tab, we are to create a template or a blueprint for our device, the template will be structured according to the type of data we are expecting from our device. Therefore, what we need to set up first is the device template.

Step 5:

Setting up the device template: From the sidebar, click on “create a device template”, you will be presented will a lot of ready-made templates, feel free to check this out but what we will do in this tutorial is to create a new one. Click on “IoT Device”, give your template a name and select “custom model”. After this, we will “Add capability” to our template, since we are expecting only Temperature and Humidity from our DHT sensor, we will add these two capabilities: Temperature and Humidity, and select “Telemetry” as the Semantic type. After this, click on views and select “Default Views”. You will be presented with how your data will be presented. I will advice you change the Temperature and Humidity to “Last Known Value”. After this click on “Save” and you can go on to publish your template.

Step 6:

Setting up the Device: After creating a blueprint for our device through the Device template, our next task is to configure the device. Select the “Devices” option and click on “Create a device”, give your device a name and an ID, and select the Device template you just created as the device template. Once this is done, click on the device you just create and click on “Connect” on the left top corner, you will be presented will information you need to connect your NodeMCU to the cloud like the DeviceID, Name, Primary Key and Public Key. Now is the time to write the code.

Step 7:

Writing the Code: I made the link to the code available. Download the code and feel free to edit it to your taste. You will need to provide your network SSID and Password.  You will also see where to insert all your device information, this can be copied and pasted directly into your code. The code can also be edited to send different data depending on your choice.

Step 8:

Once you are done setting up the code and Azure IoT central, upload the code to the NodeMCU and with a little bit of luck, you will see your Temperature and Humidity displayed in IoT Central. You can also monitor the connection via the Serial Monitor.

Step 9: Additional Resources

Github Code Link: https://github.com/adesolasamuel/NodeMCUtoAzureIoTCentral