Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Manage Devices with the Azure IoT Device Provisioning Service

The Device Provisioning Service (DPS) allows you to deploy thousands of devices without human interaction. In this lab, we will work with a single device in the DPS to better understand device deployment at scale.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 45m
Published
Clock icon Feb 25, 2022

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Set Up Device Provisioning Service

    1. Open the link for this lab in an incognito or private browser window.
    2. Enter the credentials assigned to this lab (they will be different from the credentials you see in the solution video; each student gets a unique lab session and credentials).
    3. Navigate to the resource group Overview page to confirm that 2 Azure IoT Hubs have been predeployed.
    4. Create a new Device Provisioning Service with a universally unique name in the resource group already created for the lab. Leave all other values as their defaults.
  2. Challenge

    Link 2 Hubs to the DPS and Set Allocation Policy

    1. Link the 2 predeployed hubs to the DPS.
    2. Set the default Hub Allocation Policy to Evenly weighted distribution.
    3. Return to the DPS Overview page.
  3. Challenge

    Create Individual Enrollment and Collect Metadata

    Most of the rest of the lab will be completed in a Cloud Shell terminal. Some of the values you will collect are also available in the Azure portal, but this allows you to practice using Azure CLI.

    1. Launch Cloud Shell from within the Azure Portal, choosing the Bash environment in order to use Azure CLI.
    2. When prompted to initialize storage for Cloud Shell, select Show advanced settings, and add a new the storage account and file share. Do not use an existing storage account. Note that the storage account name must be universally unique; you might want to use the random characters at the beginning of the resource group name as a part of your storage account name.
    3. Install the Azure IoT extension for Azure CLI:
      az extension add --name azure-iot
      

    Note: If you are prompted to install additional extensions when executing other commands, allow the installation of those extensions.

    1. Using Azure CLI, add an individual enrollment to the DPS you created, in the same resource group, with a symmetric key attestation type. Allow the DPS to generate the primary and secondary keys. Use something simple for the enrollment ID; it does not have to be universally unique.
    2. In order for our simulated device to connect to the provisioning service, we’ll need to retrieve 4 values: 2 from the enrollment and 2 from the DPS.
      • When the new enrollment metadata is echoed back in the terminal window, copy the registration ID and the primary key to a text document.
      • Using the Azure CLI, use a show command to view metadata for the DPS you created. When the metadata displays in the terminal window, copy the provisioning host (also known as global device endpoint) and ID scope, and paste them into your text document.
  4. Challenge

    Configure and Run Simulated Device

    1. Remaining in Cloud Shell, download the sample Node.js application by cloning the Git repository below. This sample application acts as a simulated device. Once connected to the to the internet, the device will connect to the DPS, which will use the enrollment settings to assign the device to one of the 2 Azure IoT Hubs.

      git clone https://github.com/Azure/azure-iot-sdk-node.git --recursive
      
    2. Change to the directory for provisioning samples:

      cd azure-iot-sdk-node/provisioning/device/samples
      
    3. Install the Node dependencies for the sample application:

      npm install
      
    4. In the top menu of the Cloud Shell terminal window, select the curly brackets icon to open the editor. Navigate to this directory: azure-iot-sdk-node/provisioning/device/samples.

    5. Open register_symkey.js and find the 4 variables to replace from your text document:

      1. Enrollment primary key
      2. Registration ID
      3. Provisioning host (or global device endpoint)
      4. ID scope

    **Tip: **Make sure string values are wrapped in single quotes.

    1. Save your changes.

    Tip: Look for the "..." in the upper right of the editor window to save changes and close the editor. You can also use CTRL-s to save.

    1. Back at the command prompt, run the following command to launch the application and run your simulated device:
      node register_symkey.js
      
  5. Challenge

    Confirm Enrollment and Device Hub Registration in Azure Portal

    1. Go back to the Azure portal and confirm that your individual enrollment was created in the DPS.
    2. Navigate to the 2 Azure IoT Hubs to confirm that the device is registered in exactly 1 of the 2 hubs — the DPS will decide which hub based on the allocation policy. (Given that we have only 2 hubs and 1 device, the actual choice of hubs is trivial.)

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans