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. Sign in to the Azure portal.

  2. Choose Create a resource, and then enter IoT Hub in the Search the Marketplace field.

  3. Select IoT Hub from the search results, and then select Create.

  4. On the Basics tab, complete the fields as follows:

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

    • Resource Group: Select a resource group or create a new one. To create a new one, select Create new and fill in the name you want to use. To use an existing resource group, select that resource group. For more information, see Manage Azure Resource Manager resource groups.

    • Region: Select the region in which you want your hub to be located. Select the location closest to you.

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

    Important

    Because the IoT hub will be publicly discoverable as a DNS endpoint, be sure to avoid entering any sensitive or personally identifiable information when you name it.

    Create a hub in the Azure portal

  5. Select Next: Size and scale to continue creating your hub.

    Set the size and scale for a new hub using the Azure portal

    This screen allows you to set the following values:

    • Pricing and scale tier: Your selected 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 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 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 Settings > Device-to-cloud partitions: This property relates the device-to-cloud messages to the number of simultaneous readers of the messages. Most hubs only need four partitions.

  6. For this tutorial, accept the default choices, and then select Review + create to review your choices. You see something similar to this screen.

    Review information for creating the new hub

  7. Select Create to create your new 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 an 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.