Creating an IoT Hub

Creating an IoT Hub, like almost any resource in Azure, is a simple matter. The first thing you should have though, is an Azure subscription. You can get one for free with a $200 credit from the Azure website. Once you have the subscription, you can navigate to https://portal.azure.com and start clicking away. But do you really want to create resources in the cloud using a GUI? Nah, of course you don't! We will install the Azure CLI 2.0 and create a free IoT Hub using the command line.

To install Azure CLI 2.0, head over to the documentation and follow the instructions. I installed the CLI on macOS and that could not be easier:

curl -L https://aka.ms/InstallAzureCli | bash

When installed, you should be able to call the CLI with the az command. Before doing anything use the az login command and follow the instructions on screen. Next, use az account list to list the subscriptions you have access to. If you just have the one free subscription, you should be set. Otherwise, use az account set --subscription <subscription_name_or_id to set the default subscription.

Now we are all set to create the free IoT Hub. Use the following commands:

az group create --name <resource_group_name> --location westeurope

az iot hub create --sku F1 --name <IoT_Hub_Name> --resource-group <resource_group_name>

With the first of the two commands above you create an Azure resource group in West Europe (Amsterdam). Resource groups are used to group resources (surprise!) used by an application. The second command creates the actual IoT Hub in the free tier (F1) in the new resource group. The name needs to be unique for the fully qualified domain name (FQDN) to be unique. The FQDN to access an IoT Hub is <IoTHubName>.azure-devices.net. The JSON output of the az iot hub create command will be quite verbose and gives you all the gory details about this IoT Hub. For now, we just need to know the FQDN or hostname.

In the portal, the IoT Hub will look like:

You will notice straightaway that a free IoT Hub is limited in the amount of messages it can receive. It is also limited in the amount of messages per second it can receive but with one device sending data every 10 seconds we will not reach that limit. You can find the limits in the IoT Hub documentation.

There is a lot to say about the details of an IoT Hub but this is all you need to get started and send some data.

results matching ""

    No results matching ""