Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 2.4 KB

02_emu_iothub.md

File metadata and controls

55 lines (37 loc) · 2.4 KB

Setup the Azure IoT hub

In this part, you will seamlessly connect your Pi emulator to the cloud by using Azure IoT Hub.

There are different ways to do this. You could use the Azure portal, the Cloud Shell or the Azure CLI for example. The Azure portal is very helpful to get a feeling for the possibilities of Azure and offers you a great deal of visualization if it comes to topics like monitoring. But for cloud development you either want to deploy by using Infrastructure as Code (IaC) or go with the terminal. Since IaC is worth a whole workshop in and of itself, we will use the terminal. You can choose whether you prefer your local terminal or the Azure Cloud Shell. We set both up previously.

Create the Azure IoT hub

Open up the terminal of your local machine.

  1. Add the azure-iot extension to your shell

    az extension add --name azure-iot
  2. Now we create the IoT hub in the resource group we previously created. Make sure the prefix is still stored in your terminal otherwise store it again.

    az iot hub create --name $prefix'iotpihub' --resource-group $prefix'iotpirg' --location westeurope --sku S1

    If you want to see the IoT Hub resource created in the Azure portal, go to your resource group and check whether the new resource exists.

  3. In order for the IoT Hub to be able to receive messages from and send messages to a device, you need to register it. Therefore, let's register a new device:

    az iot hub device-identity create --device-id myPi --hub-name $prefix'iotpihub'

    You can also see the new device within your IoT Hub resource under Devices: Screenshot of IoT Hub devices within Azure portal

  4. Get the primary connection string: Using PowerShell:

    $connection = (az iot hub device-identity connection-string show --device-id myPi --hub-name $prefix'iotpihub' --output tsv)

    Using bash:

    connection=$(az iot hub device-identity connection-string show --device-id myPi --hub-name $prefix'iotpihub' --output tsv)

    You can have a look if it worked:

    echo $connection

    To get the connection string from within the UI, you can click on your device within the portal and receive it manually: Screenshot of Azure portal with device connection string displayed

Go to the next steps