24 Aug 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.
- Select the New menu present in the upper-left.
- Choose Internet of Things.
- Click on Azure IoT Hub.
- Specify a name. (e.g. user name followed by iot-labs).
- Choose or create a new Resource Group.
- Choose a location that is closest to your actual location.
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.
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.
To know about keys and connection string, choose the created device.
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.
- Go to the IoT Hub.
- Select the key icon seen at the top of the blade.
- In the following blade, choose the iothubowner entry.
- Copy the Connection string-primary key that is displayed to your clipboard.
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.
From Arduino IDE, open Serial Monitor to view info of data being sent to Azure IoT Hub.
Callback and sendmessage function file
Azure Config file
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.