AZURE IOT-HUB with ESP8266

Azure IoT Hub is a cloud-based service. It allows bidirectional communication between two or more devices. This service can be mainly leveraged to connect multiple systems to the cloud and offer good control and measurement of the systems involved. 
 
Steps:  

  1. Select the New menu present in the upper-left. 
  1. Choose Internet of Things
  1. Click on AzureIoTHub. 
  1. Specify a name. (e.g. user name followed by iot-labs). 
  1. Choose or create a new Resource Group
  1. Choose a location that is closest to your actual location. 
Azure IoT Hub
Azure IoT Hub
Azure IoT Hub
Azure IoT Hub

 
A device can be created soon after creating the IoT Hub. ‘Create a device’ actually means a way of letting Azure IoT Hub realize the devices that would connect. By clicking on the ‘Add’ button, a new device can be created. 

Azure IoT Hub

 
To start with, enter a DeviceId and choose the Authentication Type to let your device use to connect with the Hub. By default, the symmetrical key is chosen, which can be altered to X509 certificate, if you want to leverage a certificate to authenticate your devices. We can see this in the later part after understanding how to make use of Device Provisioning Service (DPS) in Azure IoT. Hence, for now, let’s choose symmetric key followed by Auto-generate-key, which generates the keys for us. 

Azure IoT Hub

 
To know about keys and connection string, choose the created device. 
 

Azure IoT Hub

 
This displays information about the device that was just created. It displays ConnectionString details as well. Don’t share this information in public and ensure that it is safe as this id would be used by your device to connect to Azure IoT hub. Options such as Message to Device, Direct Method, Device twin, and a few others are not necessary for now. Let’s look at it in the future. 
 

  1. Go to the IoT Hub. 
  1. Select the key icon seen at the top of the blade. 
  1. In the following blade, choose the iothubownerentry. 
  1. Copy the Connection string-primary key that is displayed to your clipboard. 
cloud-based service

 
Arduino Code 
Header file “dht_temperature_AzureIotHub_config.h” holds info including connection string, WiFi SSID, and password. Update these config before flashing your NodeMCU.  Ensure that you give a connection string that is updated in  IOT_CONFIG_CONNECTION_STRING. 

cloud-based service

 
From Arduino IDE, open Serial Monitor to view info of data being sent to Azure IoT Hub. 

cloud-based service

 
Source code: 

cloud-based service
cloud-based service
cloud-based service
cloud-based service
Internet of Things

 
Callback and sendmessage function file 

Internet of Things

 
Azure Config file 

Internet of Things

If you still have doubts related to this topic, feel free to post your queries on the comment box below, and for more such interesting info, follow us on social media.