Configure cloud resources for device provisioning with the IoT Hub Device Provisioning Service

This tutorial shows how to set up the cloud for automatic device provisioning using the IoT Hub Device Provisioning Service. In this tutorial, you learn how to:

  • Use the Azure portal to create an IoT Hub Device Provisioning Service and get the ID scope
  • Create an IoT hub
  • Link the IoT hub to the Device Provisioning Service
  • Set the allocation policy on the Device Provisioning Service

If you don't have an Azure subscription, create a free account before you begin.

Sign in to the Azure portal

Sign in to the Azure portal.

Create a Device Provisioning Service instance and get the ID scope

Follow these steps to create a new Device Provisioning Service instance.

  1. In the upper left-hand corner of the Azure portal, click Create a resource.

  2. In the Search box, type device provisioning.

  3. Click IoT Hub Device Provisioning Service.

  4. Fill out the IoT Hub Device Provisioning Service form with the following information:

    Setting       Suggested value Description 
    Name Any unique name --
    Subscription Your subscription For details about your subscriptions, see Subscriptions.
    Resource group myResourceGroup For valid resource group names, see Naming rules and restrictions.
    Location Any valid location For information about regions, see Azure Regions.

    Enter basic information about your Device Provisioning service in the portal

  5. Click Create. After a few moments, the Device Provisioning Service instance is created and the Overview page is displayed.

  6. On the Overview page for the new service instance, copy the value for the ID scope for use later. That value is used to identify registration IDs, and provides a guarantee that the registration ID is unique.

  7. Also, copy the Service endpoint value for later use.

Create an IoT hub

This section describes how to create an IoT hub using the Azure portal.

  1. Log in to the Azure portal.

  2. Choose +Create a resource, then choose Internet of Things.

  3. Click Iot Hub from the list on the right. You see the first screen for creating an IoT hub.

    Screenshot showing creating a hub in the Azure portal

    Fill in the fields.

    Subscription: Select the subscription to use for your IoT hub.

    Resource Group: You can create a new resource group or use an existing one. To create a new one, click Create new and fill in the name you want to use. To use an existing resource group, click Use existing and select the resource group from the dropdown list. For more information, see Use resource groups to manage your Azure resources.

    Region: This is the region in which you want your hub to be located. Select the location closest to you from the dropdown list.

    IoT Hub Name: Put in the name for your IoT Hub. This name must be globally unique. If the name you enter is available, a green check mark appears.

    Important

    The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.

  4. Click Next: Size and scale to continue creating your IoT hub.

    Screenshot showing setting size and scale for a new IoT hub using the Azure portal

    On this screen, you can take the defaults and just click Review + create at the bottom.

    Pricing and scale tier: You can choose from several tiers depending on how many features you want and how many messages you send through your solution per day. The free tier is intended for testing and evaluation. It allows 500 devices to be connected to the IoT hub and up to 8,000 messages per day. Each Azure subscription can create one IoT Hub in the free tier.

    IoT Hub units: The number of messages allowed per unit per day depends on your hub's pricing tier. For example, if you want the IoT hub to support ingress of 700,000 messages, you choose two S1 tier units.

    For details about the other tier options, see Choosing the right IoT Hub tier.

    Advanced / Device-to-cloud partitions: This property relates the device-to-cloud messages to the number of simultaneous readers of the messages. Most IoT hubs only need four partitions.

  5. Click Review + create to review your choices. You see something similar to this screen.

    Screenshot reviewing information for creating the new IoT hub

  6. Click Create to create your new IoT hub. Creating the hub takes a few minutes.

Retrieve connection string for IoT hub

After your hub has been created, retrieve the connection string for the hub. This is used to connect devices and applications to your hub.

  1. Click on your hub to see the IoT Hub pane with Settings, and so on. Click Shared access policies.

  2. In Shared access policies, select the iothubowner policy.

  3. Under Shared access keys, copy the Connection string -- primary key to be used later.

    Show how to retrieve the connection string

    For more information, see Access control in the "IoT Hub developer guide."

You have now created your IoT hub, and you have the host name and IoT Hub connection string that you need to complete the rest of this tutorial.

The next step is to link the Device Provisioning Service and IoT hub so that the IoT Hub Device Provisioning Service can register devices to that hub. The service can only provision devices to IoT hubs that have been linked to the Device Provisioning Service. Follow these steps.

  1. In the All resources page, click the Device Provisioning Service instance you created previously.

  2. In the Device Provisioning Service page, click Linked IoT hubs.

  3. Click Add.

  4. In the Add link to IoT hub page, provide the following information, and click Save:

    • Subscription: Make sure the subscription that contains the IoT hub is selected. You can link to IoT hub that resides in a different subscription.

    • IoT hub: Choose the name of the IoT hub that you want to link with this Device Provisioning Service instance.

    • Access Policy: Select iothubowner as the credentials to use for establishing the link to the IoT hub.

    Link the hub name to link to the Device Provisioning Service in the portal

Set the allocation policy on the Device Provisioning Service

The allocation policy is a IoT Hub Device Provisioning Service setting that determines how devices are assigned to an IoT hub. There are three supported allocation policies:

  1. Lowest latency: Devices are provisioned to an IoT hub based on the hub with the lowest latency to the device.

  2. Evenly weighted distribution (default): Linked IoT hubs are equally likely to have devices provisioned to them. This setting is the default. If you are provisioning devices to only one IoT hub, you can keep this setting.

  3. Static configuration via the enrollment list: Specification of the desired IoT hub in the enrollment list takes priority over the Device Provisioning Service-level allocation policy.

To set the allocation policy, in the Device Provisioning Service page click Manage allocation policy. Make sure the allocation policy is set to Evenly weighted distribution (the default). If you make any changes, click Save when you are done.

Manage allocation policy

Clean up resources

Other tutorials in this collection build upon this tutorial. If you plan to continue on to work with subsequent quick starts or with the tutorials, do not clean up the resources created in this tutorial. If you do not plan to continue, use the following steps to delete all resources created by this tutorial in the Azure portal.

  1. From the left-hand menu in the Azure portal, click All resources and then select your IoT Hub Device Provisioning Service instance. At the top of the All resources page, click Delete.

  2. From the left-hand menu in the Azure portal, click All resources and then select your IoT hub. At the top of the All resources page, click Delete.

Next steps

In this tutorial, you learned how to:

  • Use the Azure portal to create an IoT Hub Device Provisioning Service and get the ID scope
  • Create an IoT hub
  • Link the IoT hub to the Device Provisioning Service
  • Set the allocation policy on the Device Provisioning Service

Advance to the next tutorial to learn how to set up your device for provisioning.