Creating a Azure IoT hub

In this blog we will see how to create a Azure IoT hub so that we post messages to Azure IoT hub. IoT hub has different SDKs  for different devices to allow devices to communicate with the Cloud. For NodeMCU there is no SDK. The good news is that you can communicate with IoT hub using MQTT. NodeMCU has support for MQTT (with TLS support).

Account Setup:

you need to signup for the account first

https://azure.microsoft.com

Once you are done with the account setup , you will be redirected to Azure portal.

Azure_search_iot_hub

Search for IoT hub as shown above.  If you click on the IoT hub , you will get a option to add new instance.

Azure_Add_iot_hub

Fill the required fields. Check DM (device management) box if not checked already.

Azure_create_iot_hub

Once account it is created, it will take some time for the instance to be available.

Azure_IoT_hub_hostname

Note down the hostname,you need add a device to Device identity registry to be able to send messages from NodeMCU. It exposes a REST API using we which we can create new devices. There are Service SDKs available for different platforms. You can use the SDKs or the REST API. There is Device Explorer application which lets you to manage devices. This is the easiest option to register a new device.

click on keys symbol, then select “iothubowner” policy.  copy the primary key , secondary  key and the connection string . you need them to create a new device in IoT hub.

Azure_IoT_hub_hostname

 

 

Download the DE( Device Explorer ) from here . Install and open the DE, paste your connection string and click update.

DE_ConnectionString

Next you need to register your device

DE -> Management -> Create

Click on create , It will ask for device Id, you can use any unique value, I will be using NodeMCU chip id.

print(node.chipid())

If the device creation is successful the management screen should show something like this.

DE_Mangement

 

SAS Token:

Next you need generate a SAS token click on SAS Token button. Update TTL to 350 (this is token validity), then click on generate. String starting from Shared Access … is the SAS token. You need to provide this token as password in MQTT connection details. Now you can move on to connecting your NodeMCU with the IoT hub.

DM_SAS_token

Add a Comment

Your email address will not be published. Required fields are marked *