How to Send Data to Microsoft Azure IoT Central Using NodeMCU

by Adesolasamuel in Circuits > Microcontrollers

1080 Views, 1 Favorites, 0 Comments

How to Send Data to Microsoft Azure IoT Central Using NodeMCU

Tumpnails.jpg

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

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.

NodeMCU Azure (Time 0_01_46;11).jpg

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

NodeMCU Azure (Time 0_02_15;20).jpg
NodeMCU Azure (Time 0_02_27;26).jpg
NodeMCU Azure (Time 0_03_53;08).jpg

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.

NodeMCU Azure (Time 0_05_55;09).jpg

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.

NodeMCU Azure (Time 0_06_23;23).jpg
NodeMCU Azure (Time 0_06_48;05).jpg
NodeMCU Azure (Time 0_07_20;21).jpg
NodeMCU Azure (Time 0_08_01;11).jpg
NodeMCU Azure (Time 0_09_22;21).jpg
NodeMCU Azure (Time 0_09_47;03).jpg
NodeMCU Azure (Time 0_10_45;23).jpg

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.

NodeMCU Azure (Time 0_11_38;19).jpg
NodeMCU Azure (Time 0_11_50;25).jpg
NodeMCU Azure (Time 0_13_08;03).jpg
NodeMCU Azure (Time 0_13_36;17).jpg

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.

NodeMCU Azure (Time 0_15_26;11).jpg
NodeMCU Azure (Time 0_18_37;15).jpg
NodeMCU Azure (Time 0_20_43;16).jpg

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.

NodeMCU Azure (Time 0_21_07;28).jpg

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.

Additional Resources

How to Send Data from NodeMCU to Azure IoT Central

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