Getting Started With Azure IoT Hub And Devices

Introduction

 
Azure IoT Hub is a managed service of the Azure cloud which acts as central bi-directional message hub to exchange between IoT application and devices. Azure IoT hub allows you to create reliable and secure communication between IoT devices and Cloud apps. The devices can be virtual. It supports bi-directional communication; i.e. from the device to the cloud and from the cloud to the device.
 

Setting up an Azure IoT Hub


There are multiple ways to create Azure IoT Hub such as using Azure portal, Azure PowerShell, Azure CLI, etc. In this article, I will explain how to create and manage IoT hub using Azure portal.
 
To create an IoT hub, you must have an Azure account. Following are the steps to create an IoT hub using Azure portal.
 
Step 1
 
Sign into the Azure Portal

Step 2
 
Click on “Create a resource” button from the portal home screen.
 
Getting Started With Azure IoT Hub And Devices
Step 3
 
This will list down all available service. Select “Internet of Things” from left panel and click on “IoT Hub” from right panel. You can also search required service from search textbox.  
 
Getting Started With Azure IoT Hub And Devices 
Step 4
 
There are some mandatory information you need to fill up for IoT hub. Following information need to fill in "Basic" tab.
  • Subscription: select the subscription that you want to use to create IoT hub
  • Resource Group: select the existing resource group or create new one
  • Region: select region in which you want to host your IoT hub. You can select region that is very near to your devices.
  • IoT Hub Name: enter IoT hub name. It must be unique at global level 
Getting Started With Azure IoT Hub And Devices
 
There are some other tabs also available such as Networking, Size and scale, and Tags. These tabs have some default option selected. You may change those default options base on your requirement.
 
Click on “Review+ create” button, once you setting up all fields. It summarizes all the option that you have selected to create IoT hub. You can also modify the option if something wrong option has been selected by selecting particular tab.
 
Once you fine with selected options, click on “Create” button to create IoT hub.
 
Getting Started With Azure IoT Hub And Devices
 
It takes some time to create and host your IoT hub. Once your IoT hub hosted and available for use, you will get notification.
 
Getting Started With Azure IoT Hub And Devices
 
You can also modify the setting of the IoT hub once you create have created it.
 

Shared access policies


You can view and modify the IoT hub shared access policies by clicking on "Shared access policy" from left panel under the setting section. There are some pre-defined shared access policies that are defined. You can add your custom shared access policy. Basically, it contains the permission of IoT hub access. The access policies contain the key and connection string that can be use to connect IoT hub from the devices.
 
You can also view, modify and delete the pre-defined access policies.
 
Getting Started With Azure IoT Hub And Devices

To add new access policy, click on “+ Add” button. Here, you have to provide policy name and set of permission associate with the policy.
 
Getting Started With Azure IoT Hub And Devices
 
There are four permissions that you can set to policy.
  • Registry Read: It grants the read access rights to the identity registry
  • Registry write: It grants the write access rights to the identity registry
  • Service connect: It grants permission for access service endpoints. When you enable this option, one can connect service end point and send and receive messages from the device and also read and modify device twin data
  • Device connect: It grants the permission for sending receiving message. It is used to send and receive message from IoT hub. It also used to read and modify device twin data.

Creating new Devices in IoT Hub


The devices can be created under the IoT hub. To create new device, select "IoT devices" from left panel under the Explorer section and then click on "+New" button.
 
Getting Started With Azure IoT Hub And Devices
 
Provide the name of device and click on save button. Here, Azure provides the option to create custom primary key/secondary key. You can also generate a key automatically.
 
Getting Started With Azure IoT Hub And Devices
 
Once you have created a device, you can open the device from IoT device list and view / copy the keys and connection strings.
 
Getting Started With Azure IoT Hub And Devices
 

Delete the IoT devices

 
You can also delete the IoT devices. To delete devices, select the devices from the list and click on “Delete” button. It will ask for the conformation and when you confirm, it will delete the IoT device.
 
Getting Started With Azure IoT Hub And Devices
 

Delete IoT hub


To delete the IoT hub, select the IoT hub and then click on the “Overview” section from left panel. Now, click on “Delete” button from the right panel.
 
Getting Started With Azure IoT Hub And Devices 
 
It will ask for confirmation and you have to type the name of the Iot hub to confirmthen click on delete button. Once you delete the IoT hub, all the devices are permanently deleted.
 
Getting Started With Azure IoT Hub And Devices 
 

Summary


Azure IoT Hub is a managed service of Azure cloud which acts as central bi-directional message hub to exchange between IoT application and devices. It allows you create reliable and secure solution for connecting billions of devices. You can use Azure IoT device SDK to build device software. It supports many languages such as C, C#, Java, Python and Node.js. The IoT hub supports many protocols for connecting devices such as Https, AMQP, MQTT and AMQP/MQTT over WebSocket.