Skip to content

06 IoT Hub and IoT Central config

Dave Glover edited this page Feb 9, 2022 · 2 revisions

Azure IoT Hub and IoT Central configuation

Connecting EdgeDevX apps to Azure IoT Hub and IoT Central.

Install the Azure CLI tools

Follow the How to install the Azure CLI guide.

The IoT extension for the Azure CLI provides the compute-device-key command for generating derived device keys. This command can be used from Windows-based, Linux systems, and macOS systems from PowerShell or a Bash shell with the Azure CLI tools installed.

DPS and IoT Central

Create an IoT Central application

Follow the Create an IoT Central application guide.

Create an IoT Central enrollment group

  1. Select Administration from the sidebar menu.
  2. Select Device connection.
  3. Select +New to create a new enrollment group.
  4. Name your group.
  5. Select Shared access signature attestation type.
  6. Select Save

Create a device key

  1. Open a Terminal window on your computer and run the compute-device-key command to generate a device derived key. Notes.

    • You will likely be prompted to insrall the azure-iot extension. Select Y, and press Enter..
    • The primary key is the primary key generated your newly created enrollment group.
    • The device id name is any arbitary/sensible name.
    az iot central device compute-device-key --pk {primaryKey} --device-id {deviceid}
  2. Copy the derived key somewhere safe as you'll need to configure the Visal Studio Code launcher.

DPS and IoT Hub

You need to create Azure IoT Hub and Azure DPS services. Follow this Quickstart: Set up the IoT Hub Device Provisioning Service with the Azure portal.

Create a DPS enrollment group

  1. Open the DPS blade from the Azure managemnt portal.
  2. Select Manage enrollments.
  3. Select Add enrollment group.
  4. Name your group.
  5. Select Symmetric Key attestation type.
  6. Select Save.

Create a derived device key

  1. Open your newly created enrollment group.

  2. Copy the primary public key to notepad.

  3. Open a Terminal window on your computer and run the following command to generate a device derived key. Notes:

    • You will likely be prompted to insrall the azure-iot extension. Select Y, and press Enter.
    • The primary key is the primary key generated your newly created enrollment group.
    • The device device id is any arbitary/sensible name.
    az iot dps compute-device-key --key <your_group_enrollment_primary_key> --registration-id <your_device_id>
  4. Copy the derived key somewhere safe as you'll need to configure the Visal Studio Code launcher.

Run the application from Visual Studio Code

Configure Visual Studio Code launcher

You need to pass the Azure IoT DPS or IoT Central and derived device key to your application.

The following steps assume you have opened one of the EdgeDevX.Examples with Visual Studio Code.

  1. Go to and open the .vscode/launch.json file in VS Code.

  2. Update the [args] json property for the build configuration.

  3. Add the following information.

    • Your DPS or IoT Central ID Scope.
    • Your device id.
    • Your derived device key.

    For example:

    "args": ["-s", "<YOUR_SCOPE_ID>", "-d", "<YOUR_DEVICE_ID>", "-k", "<YOUR_DERIVED_DEVICE_KEY>"],

  4. Save the launch.json file