Getting Started With Azure IoT Hub

Posted on April 18, 2021 · 3 mins read

Azure IoT Hub is a managed cloud service which provides bi-directional communication between the cloud and IoT devices. It is a platform as a service for building IoT solutions. Being an azure offering, it has security and scalability built-in as well as making it easy to integrate with other Azure services.

This blog post is an introduction to Azure IoT Hub and how to get one up and running.

What we will need:

Creating an IoT Hub

We will be using Azure Powershell to create an Azure IoT Hub. Below are some Powershell commandlets that we can use to check that we are signed in and using the correct Azure subscription.

    PS D:\Workspace\IoTHub> Get-AzContext
    PS D:\Workspace\IoTHub> Connect-AzAccount
    WARNING: To sign in, use a web browser to open the page and enter the code ABCDEFGHIJ to authenticate.
    PS D:\Workspace\IoTHub> Get-AzContext
    Free Trial (abc12345-1234-abcd-1234-abc…
    PS D:\Workspace\IoTHub>

Note that Get-AzContext returns nothing if we are not signed in (i.e. no context). But after signing in, Get-AzContext should return our subscription details.

Once we are logged in, we will need to create a resource group (basically a logical container). Every resource we create in Azure needs to be associated with a resource group.

    PS D:\Workspace\IoTHub> New-AzResourceGroup -Name 'rg-sea-aniotodyssey' -Location 'southeastasia' -Verbose -Force -ErrorAction Stop
    VERBOSE: Performing the operation "Replacing resource group ..." on target "rg-sea-aniotodyssey".
    VERBOSE: 8:50:49 pm - Created resource group 'rg-sea-aniotodyssey' in location 'southeastasia'
    ResourceGroupName : rg-sea-aniotodyssey
    Location          : southeastasia
    ProvisioningState : Succeeded
    Tags              :
    ResourceId        : /subscriptions/abc12345-1234-abcd-1234-abcdef123456/resourceGroups/rg-sea-aniotodyssey
    PS D:\Workspace\IoTHub>

We can now proceed to creating an Iot Hub. One thing I want to point out is the SkuName parameter. Depending on our needs, I am inclined to use the F1 (which is the free tier) for prototyping purposes and basic usage. This should help avoiding unexpected bills.

    PS D:\Workspace\IoTHub> New-AzIotHub -ResourceGroupName 'rg-sea-aniotodyssey' -Name 'ih-sea-aniotodyssey' -SkuName 'F1' -Units 1 -Location 'southeastasia'
    Id             : /subscriptions/abc12345-1234-abcd-1234-abcdef123456/resourceGroups/rg-sea-aniotodyssey/providers/Microsoft.Devices/IotHubs/ih-sea-aniotodyssey
    Name           : ih-sea-aniotodyssey
    Type           : Microsoft.Devices/IotHubs
    Location       : southeastasia
    Tags           : {}
    Subscriptionid : abc12345-1234-abcd-1234-abcdef123456
    Resourcegroup  : rg-sea-aniotodyssey
    Properties     : Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubProperties
    Sku            : Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubSkuInfo
    PS D:\Workspace\IoTHub>

There we have it, we have just created an Azure IoT Hub hosted in a data center in South East Asia.

New IoT Hub created New IoT Hub created