Azure IoT hub is a cloud service that enables bidirectional communication between devices. This service can be used for connecting various systems to the cloud and provides means of control and measurement of the systems. In this blog we are going to demonstrate how to use azure iot hub esp8266.Steps: –

  1. Click on the New menu option in the upper-left.
  2. Select Internet of Things.
  3. Select Azure IoT Hub.
  4. Give it a name. (e.g. your name followed by iot-labs).
  5. Select or create a new Resource Group.
  6. Select a location. Choose the one closest to your physical location.

Once the IoT Hub is created, we can then create a device. When I say ‘create a device’ its just a way of letting Azure IoT Hub know about devices which would connect. We can create a new device by clicking on the Add button.

Please proceed with entering a DeviceId and then select the Authentication Type that you want your device to use while connecting to the Hub. By default symmetrical key is selected which can be changed to X509 certificate if you intend to use a certificate while authenticating your devices. We would cover that later once we see how to use Device Provisioning Service (DPS) in Azure IoT. For now let’s select symmetric key and have the option Auto-generate-key checked which would generate the keys for us.

Click on the device created to see the details about keys and connection string.

This shows details about the device which we just created. It shows ConnectionString info as well. Please make sure you keep this information secure and don’t share it in public since this is the id which your device would use to connect to Azure IoT hub. You can see the options like Message to Device, Direct Method, Device twin etc., which can be ignored for now. We would cover these later in our next post.

  1. Navigate into the IoT Hub.
  2. Click on the key icon at the top of the blade.
  3. In the next blade, click on the iothubowner entry.
  4. Copy the Connection string-primary key to your clipboard.


Arduino Code

Header file “dht_temperature_AzureIotHub_config.h” has details about connection string and WiFi SSID and password. Please update these config and  then flash your NodeMCU .Please make sure you are giving updated connection string in  IOT_CONFIG_CONNECTION_STRING.

You can open Serial Monitor from Arduino IDE to view the details of data being send to Azure IoT Hub.

Source code:-

Callback function and sendmessage function file

Azure Config file

If you are still facing issue regarding azure iot hub esp8266 Feel free to Ask Doubts in the Comment Box Below and Don’t Forget to Follow us on 👍 Social Networks😉