Skip to main content

Registering a Device with Azure IoT Hub

Hands-On Lab

 

Photo of Shawn Johnson

Shawn Johnson

Azure Training Architect II in Content

Length

00:45:00

Difficulty

Intermediate

An Azure IoT Hub by itself isn't much of an IoT solution. As a matter of fact, it isn't one at all. Without devices to send telemetry to the IoT hub, the hub itself is like an ice cream shop with zero flavors. In this hands-on lab, we will create a device in a pre-provisioned Azure IoT hub and then, using a Raspberry Pi simulator, connect that device to our IoT hub. We will then be able to see connectivity between the device and our hub.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Registering a Device with Azure IoT Hub

Introduction

An Azure IoT Hub by itself isn't much of an IoT solution. As a matter of fact, it isn't one at all. Without devices to send telemetry to the IoT hub, the hub itself is like an ice cream shop with zero flavors. In this hands-on lab, we will create a device in a pre-provisioned Azure IoT hub and then, using a Raspberry Pi simulator, connect that device to our IoT hub. We will then be able to see connectivity between the device and our hub.

Solution

Log in to the Azure Portal using the provided credentials.

Register the Device with the IoT Hub

  1. On the Overview page, note the five-character suffix at the end of the storage account name — we'll use this throughout the lab as we name our Azure resources.

  2. Click the Cloud Shell icon (>_) in the upper-right of the screen.

  3. Click Bash.

  4. Click Show advanced settings, and set the following values:

    • Subscription: Leave default
    • Resource group: Leave default
    • Cloud Shell region: West US
    • Storage account: Use existing
    • File share: Use existing, and enter cloudshell
  5. Click Attach storage.

  6. In Cloud Shell, install the Azure IoT extension for CLI:

    az extension add --name azure-iot
  7. Register the device (XXXXX is the five-character suffix for the lab resources):

    az iot hub device-identity create --device-id IoTDevice1 --hub-name iothub-XXXXX
  8. Obtain the connection string for the device (XXXXX is the five-character suffix for the lab resources):

    az iot hub device-identity show-connection-string --hub-name iothub-XXXXX --device-id IoTDevice1 --output table
  9. Copy this connection string to your clipboard.

Configure the Raspberry Pi Azure IoT Online Simulator

  1. Access the simulator at https://azure-samples.github.io/raspberry-pi-web-simulator/.

  2. Change the following line (line 15), replacing the text between the single quotes with the connection string you copied in the previous objective:

    const connectionString = '[Your IoT hub device connection string]';

Verify Connectivity to the IoT Hub

In the Raspberry Pi Azure IoT Online Simulator, click Run. If the previous objective was performed correctly, the "LED" light will blink, and you should see messages from the "device" being sent to the IoT hub, like so:

IoT Device Connected!

Conclusion

Congratulations on successfully completing this hands-on lab!