Registering a Device with Azure IoT Hub

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Register the Device with the IoT Hub
  1. Access the CLI by using Azure Cloud Shell, logging in with the credentials provided in the lab.

  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: Use Existing
    • Cloud Shell region: Use the same region as your lab provided storage account.
    • Storage account: Use existing
    • File share: Create new, and enter cloudshell
  5. Click Create storage.

  6. 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!

Additional Resources

You have recently been hired by Parktronics, a monitoring company that works with local, state, and national park services. They have decided to use Azure IoT to develop Gatekeeper, a solution that will monitor entry and exit gates to ensure they are closed and locked at closing time.

You've been tasked with a proof-of-concept of the Gatekeeper solution. Prior to shipping out a device for use in your proof-of-concept, you decide to use a simulated device to test connectivity to an Azure IoT hub.

You will need to:

  • Register a device with Azure IoT Hub.
  • Configure the device to connect to the Azure IoT hub.
  • Send sample telemetry data to the hub and verify data is being sent.

If you get stuck, feel free to check out the solution video or the detailed instructions under each objective. Good luck!

Tools

To register the device with IoT Hub, you will be using the Azure CLI. You can access the CLI by using Azure Cloud Shell.

  1. Click the Cloud Shell icon (>_) in the upper-right of the screen.
  2. Click Bash.
  3. Click Show advanced settings, and set the following values:
    • Subscription: Leave default
    • Resource group: Use Existing
    • Cloud Shell region: Use the same region as your lab provided storage account.
    • Storage account: Use existing
    • File share: Create new, and enter cloudshell
  4. Click Create storage.

We will be using the Raspberry Pi Azure IoT Online Simulator as our device in this lab. You can access the simulator at https://azure-samples.github.io/raspberry-pi-web-simulator/.

Lab Suffix

Pre-deployed lab resources will all end with a unique five-character suffix. Make note of this suffix, as you may need it when naming resources during the lab.

WARNING: Be Prepared for UI Changes

Given the fluid nature of Microsoft cloud tools, you may experience user interface (UI) changes that were made following the development of this hands-on lab that do not match up with lab instructions. When any such changes are brought to our attention, we will attempt to update the content accordingly. However, if changes occur, students will have to adapt to the changes and work through them in the hands-on labs as needed.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?