Getting Started With Azure IoT Hub


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.

In this tutorial we will demonstrate how Azure IoT Hub works by creating an IoT Hub.

What we will need:

Creating an IoT Hub

We will be using Azure Powershell to create an Azure IoT Hub.

Ok just a bit of a separate exercise. I recently create some Azure resources but when I logged into Azure Portal, and for the life of me I could not find the resources I created. It was only after some times in the rabbit hole that I realised I was not using the correct Azure account. So when we have multiple Azure accounts or multiple subscriptions within an Azure account, we should ensure that we are using the right Azure context. Below are some Powershell commands that we can use to check that we are using the right context.

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

Now that we are logged in, we need to create a resource group. Every resource we create on 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 testing and prototyping purposes. This should help against 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 just created an Azure IoT Hub hosted in a data center in South East Asia.

Categories: .NET, Azure, Internet of things

1 comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: