Azure IoT Workshop | Real-Time Asset Tracking

End-to-end IoT workshop focusing on a real-time asset tracking scenario.

View on GitHub

Connecting a device to Azure IoT

In this section, we are going to setup the messaging infrastructure needed to connect Contoso Art Shipping’s asset tracking devices. For the context of this lab, the asset tracking device will be the MXChip developer kit running a custom firmware that exposes sensor telemetry using IoT Plug-and-Play.

Learning goals

Steps

Create a resource group

  1. Create an Azure resource group to collect and manage all the application resources we will be provisioning and using during the workshop.

    Resource Group

  2. Click on + Add button

    Add Resource Group

  3. Enter Resource group name, Select subscription and region. Click on Review + Create, and after reviewing, click on Create.

    NOTE:

    • Resource Group Name: Use name of your choice.
    • Region: During public preview, IoT Plug and Play is available in the North Europe, Central US, and Japan East regions. Although we are only creating a resource group at this stage, please make sure you create it in one of these regions to avoid potential mistakes later on.

Create Resource Group Submit

Create an Azure IoT Hub and an Azure Device Provisioning Service

Follow the instructions from Azure IoT DPS documentation to provision an Azure IoT Hub, a Device Provisioning Service, and linking the two together.

IMPORTANT:

Make sure to create your IoT Hub in one of the following regions in order to get PnP support during the public preview: North Europe, Central US or Japan East.

In order to easily find your resources later, you will want to create the IoT Hub and the Device Provisioning Service in the same Resource Group you’ve created in the previous step.

Once your services are properly provisioned and your DPS service is linked to your IoT Hub instance, you need to create a DPS Group Enrollment. As opposed to single enrollments where you individually “whitelist” and create a set of credentials for every device, a group enrollment can provide you with more flexibility by having a unique set of credentials for all the devices in the same group.

In the Azure Portal, navigate to the Device Provisioning Service you have just created.

In your provisioning service:

  1. Click Manage enrollments.
  2. Click the Add enrollment group button at the top.
  3. When the “Add Enrollment Group” panel appears, enter the information for the enrollment list entry. Group name is required (as a suggestion, you can name the enrollment group “AssetTrackers”). Select “Symmetric Key” for Attestation Type.
  4. Click Save. On successful creation of your enrollment group, you should see the group name appear under the Enrollment Groups tab.
  5. Select the newly created Enrollment group in the Enrollment Groups tab.
  6. Click the Copy icon in Primary Key in order to copy the symmetric key that has been generated for this enrollment group to your clipboard. You will need it in the following step.

    NOTE:

    For production use cases, you will want to make sure your device is storing the group symmetric key in some form of secure storage and can’t easily be extracted from the device. If your group symmetric key is compromised, it potentially allows anyone to provision devices in your environment.

Connect the MXChip Plug-and-Play asset tracker

Follow the instructions available here in order to program your MXChip device with a firmware that is PnP compatible, and reports simulated latitude/longitude in addition to real telemetry coming from its sensors.

In addition to your Wi-Fi credentials, you will need to enter the following information for the Azure IoT DPS Settings:

When you’ve completed these instructions, your MXChip device should be connected to IoT Hub, and sending telemetry information as well as listening to commands. In the next step we will actually explore the device capabilities, using the Azure IoT Device Explorer.

Explore the capabilities of the asset tracking device

  1. Download and install the latest version of the Azure IoT Explorer tool from the Github release page.

  2. Enter your IoT Hub connection string. You can find this information in the Azure portal: open your IoT Hub resource, then go to Shared access policies pane, and click on iothubowner. You can then copy the Connection string—primary key.

    Azure IoT Explorer - Connection string

  3. Feel free to check the Remember my connection string option, then click Connect.

  4. Select your device from the list that is now displayed. At this point, it should show up as “Connected”.

    Azure IoT Explorer - Device list

  5. Use the entries in “IoT Plug and Play components” to explore the capabilities of the device. For example:

    • Navigate to urn:azureiot:DeviceManagement:DeviceInformation:1 > Properties (non-writable). Note how the device is reporting about its hardware capabilities in a standard way. As a solution builder, you can expect any Plug-and-Play device to always expose these properties, which helps rationalizing device management efforts.
    • Navigate to urn:mxchip:built_in_sensors:1 > Telemetry. Click on the Start button and observe the flow of telemetry information being sent every 5 seconds. Also observe how the tool provides you with useful metadata about sensor data, thanks to PnP.
    • Navigate to urn:mxchip:screen:1 > Commands. Test any of the available commands, and enjoy bidirectional communication with your device!
    • Navigate to urn:contosoartshipping:position:1 > Interface. Often times, the PnP interfaces a device is implementing will be available through either a public Microsoft repository, or a private/company one. There is also an option for the device to implement the urn:azureiot:ModelDiscovery:ModelDefinition:1 interface, which effectively allows for the interface to be automatically discovered from the cloud by retrieving it from the device. Note how the UI is indicating Source: On the connected device, reflecting the fact that the custom ‘position’ interface has not been found in PnP repository, and instead retrieved from the device.

Going further

If you are interested in exploring further, you may want to think about how to best solve the following problems:

Wrap-up and Next steps

In this section, we have setup our messaging infrastructure, and used the Azure IoT Explorer to check that our device is properly connected.

In the next section, we will setup the infrastructure needed for storing, visualizing, and querying our IoT data.