Skip to content

Commit 9d33598

Browse files
authored
Merge pull request #204951 from JimacoMS4/update-custom-allocation-topics-dps
Refactor custom allocation topics
2 parents e6beb34 + 30c05c4 commit 9d33598

21 files changed

+610
-769
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29139,6 +29139,11 @@
2913929139
"redirect_url": "/azure/iot-dps/quick-enroll-device-tpm",
2914029140
"redirect_document_id": false
2914129141
},
29142+
{
29143+
"source_path_from_root": "/articles/iot-dps/how-to-use-custom-allocation-policies.md",
29144+
"redirect_url": "/azure/iot-dps/tutorial-custom-allocation-policies",
29145+
"redirect_document_id": false
29146+
},
2914229147
{
2914329148
"source_path_from_root": "/articles/app-service/environment/app-service-app-service-environment-web-application-firewall.md",
2914429149
"redirect_url": "/azure/app-service/environment/integrate-with-application-gateway",

articles/iot-dps/concepts-custom-allocation.md

Lines changed: 275 additions & 0 deletions
Large diffs are not rendered by default.

articles/iot-dps/concepts-device-reprovision.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Depending on the scenario, a device could send a request to a provisioning servi
5858
* **Never re-provision**: The device is never reassigned to a different hub. This policy is provided for managing backwards compatibility.
5959

6060
> [!NOTE]
61-
> DPS will always call the custom allocation webhook regardless of re-provisioning policy in case there is new [ReturnData](how-to-send-additional-data.md) for the device. If the re-provisioning policy is set to **never re-provision**, the webhook will be called but the device will not change its assigned hub.
61+
> DPS will always call the custom allocation webhook regardless of re-provisioning policy in case there is new [ReturnData](concepts-custom-allocation.md#use-device-payloads-in-custom-allocation) for the device. If the re-provisioning policy is set to **never re-provision**, the webhook will be called but the device will not change its assigned hub.
6262
6363
When designing your solution and defining a reprovisioning logic there are a few things to consider. For example:
6464

articles/iot-dps/concepts-service.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The service-level setting that determines how Device Provisioning Service assign
4040

4141
* **Static configuration via the enrollment list**: specification of the desired IoT hub in the enrollment list takes priority over the service-level allocation policy.
4242

43-
* **Custom (Use Azure Function)**: A [custom allocation policy](how-to-use-custom-allocation-policies.md) gives you more control over how devices are assigned to an IoT hub. This is accomplished by using custom code in an Azure Function to assign devices to an IoT hub. The device provisioning service calls your Azure Function code providing all relevant information about the device and the enrollment to your code. Your function code is executed and returns the IoT hub information used to provisioning the device.
43+
* **Custom (Use Azure Function)**: A [custom allocation policy](concepts-custom-allocation.md) gives you more control over how devices are assigned to an IoT hub. This is accomplished by using custom code in an Azure Function to assign devices to an IoT hub. The device provisioning service calls your Azure Function code providing all relevant information about the device and the enrollment to your code. Your function code is executed and returns the IoT hub information used to provisioning the device.
4444

4545
## Enrollment
4646

articles/iot-dps/dps-faq.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ sections:
3535
- question: |
3636
How does the health of an IoT hub affect device provisioning?
3737
answer: |
38-
Currently DPS doesn't check the health of an IoT hub before assigning devices. DPS will continue to try to assign devices to an IoT hub that is down based on its configured allocation policy. For example, if the configured allocation policy is *Lowest latency* and DPS has a linked IoT hub in region A (hub A) and one in region B (hub B), it will assign a device trying to provision from region A to hub A, even if hub A is down. To factor in IoT hub health when provisioning devices, you can implement a custom allocation policy with your own monitoring logic based on [IoT Hub diagnostics](../iot-hub/monitor-iot-hub.md) or your own user-defined metrics. To learn more about custom allocation policies, see [How to use custom allocation policies](how-to-use-custom-allocation-policies.md).
38+
Currently DPS doesn't check the health of an IoT hub before assigning devices. DPS will continue to try to assign devices to an IoT hub that is down based on its configured allocation policy. For example, if the configured allocation policy is *Lowest latency* and DPS has a linked IoT hub in region A (hub A) and one in region B (hub B), it will assign a device trying to provision from region A to hub A, even if hub A is down. To factor in IoT hub health when provisioning devices, you can implement a custom allocation policy with your own monitoring logic based on [IoT Hub diagnostics](../iot-hub/monitor-iot-hub.md) or your own user-defined metrics. To learn more about custom allocation policies, see [Understand custom allocation policies](concepts-custom-allocation.md).
3939
- question: |
4040
Can multiple DPS instances provision devices to the same IoT hub?
4141
answer: |
42-
Yes; however, built-in allocation policies apply to each DPS instance individually, so load balancing across multiple IoT hubs is not possible when using the built-in DPS policies. Instead, you can use a custom allocation policy to implement load balancing when using multiple DPS instances. To learn more about custom allocation policies, see [How to use custom allocation policies](how-to-use-custom-allocation-policies.md).
42+
Yes; however, built-in allocation policies apply to each DPS instance individually, so load balancing across multiple IoT hubs is not possible when using the built-in DPS policies. Instead, you can use a custom allocation policy to implement load balancing when using multiple DPS instances. To learn more about custom allocation policies, see [Understand custom allocation policies](concepts-custom-allocation.md).
4343
- question: |
4444
How can I get an authorization token to use for REST service operations?
4545
answer: |

articles/iot-dps/how-to-send-additional-data.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,71 @@ title: How to transfer a payload between device and Azure Device Provisioning Se
33
description: This document describes how to transfer a payload between device and Device Provisioning Service (DPS)
44
author: kgremban
55
ms.author: kgremban
6-
ms.date: 12/03/2021
6+
ms.date: 09/21/2022
77
ms.topic: conceptual
88
ms.service: iot-dps
99
services: iot-dps
1010
---
1111

1212
# How to transfer payloads between devices and DPS
1313

14-
Sometimes DPS needs more data from devices to properly provision them to the right IoT Hub, and that data needs to be provided by the device. Vice versa, DPS can return data to the device to facilitate client-side logic.
14+
Devices that register with DPS are required to provide a registration ID and valid credentials (keys or X.509 certificates) when they register. However, there may be IoT solutions or scenarios in which additional data is needed from the device. For example, a custom allocation policy webhook may use information like a device model number to select an IoT hub to provision the device to. Likewise, a device may require additional data in the registration response to facilitate its client-side logic. DPS provides the capability for devices to both send and receive an optional payload when they register.
1515

1616
## When to use it
1717

18-
This feature can be used as an enhancement for [custom allocation](./how-to-use-custom-allocation-policies.md). For example, you want to allocate your devices based on the device model without human intervention. In this case, you can configure the device to report its model information as part of the [register device call](/rest/api/iot-dps/device/runtime-registration/register-device). DPS will pass the device’s payload to the custom allocation webhook. Then your function can decide which IoT hub the device will be provisioned to based on the device model information. If needed, the webhook can return data back to the device as a JSON object in the webhook response.
18+
Common scenarios for sending optional payloads are:
19+
20+
* [Custom allocation policies](concepts-custom-allocation.md) can use the device payload to help select an IoT hub for a device or set its initial twin. For example, you may want to allocate your devices based on the device model. In this case, you can configure the device to report its model information when it registers. DPS will pass the device’s payload to the custom allocation webhook. Then your webhook can decide which IoT hub the device will be provisioned to based on the device model information. If needed, the webhook can also return data back to the device as a JSON object in the webhook response. To learn more, see [Use device payloads in custom allocation](concepts-custom-allocation.md#use-device-payloads-in-custom-allocation).
21+
22+
* [IoT Plug and Play (PnP)](../iot-develop/overview-iot-plug-and-play.md) devices *may* use the payload to send their model ID when they register with DPS. You can find examples of this usage in the PnP samples in the SDK or sample repositories. For example, [C# PnP thermostat](https://github.com/Azure-Samples/azure-iot-samples-csharp/blob/main/iot-hub/Samples/device/PnpDeviceSamples/Thermostat/Program.cs) or [Node.js PnP temperature controller](https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/pnp_temperature_controller.js).
23+
24+
* [IoT Central](../iot-central/core/overview-iot-central.md) devices that connect through DPS *should* follow [IoT Plug and Play conventions](..//iot-develop/concepts-convention.md) and send their model ID when they register. IoT Central uses the model ID to assign the device to the correct device template. To learn more, see [Device implementation and best practices for IoT Central](../iot-central/core/concepts-device-implementation.md).
1925

2026
## Device sends data payload to DPS
2127

22-
When your device is sending a [register device call](/rest/api/iot-dps/device/runtime-registration/register-device) to DPS, The register call can be enhanced to take other fields in the body. The body looks like the following:
28+
When your device calls [Register Device](/rest/api/iot-dps/device/runtime-registration/register-device) to register with DPS, it can include additional data in the **payload** property. For example, the following JSON shows the body for a request to register using TPM attestation:
2329

2430
```json
2531
{
2632
"registrationId": "mydevice",
2733
"tpm": {
28-
"endorsementKey": "stuff",
29-
"storageRootKey": "things"
34+
"endorsementKey": "xxxx-device-endorsement-key-xxxx",
35+
"storageRootKey": "xxx-device-storage-root-key-xxxx"
3036
},
3137
"payload": { A JSON object that contains your additional data }
3238
}
3339
```
3440

41+
The **payload** property must be a JSON object and can contain any data relevant to your IoT solution or scenario.
42+
3543
## DPS returns data to the device
3644

37-
If the custom allocation policy webhook wishes to return some data to the device, it will pass the data back as a JSON object in the webhook response. The change is in the payload section below.
45+
DPS can return data back to the device in the registration response. Currently, this feature is exclusively used in custom allocation scenarios. If the custom allocation policy webhook needs to return data to the device, it can pass the data back as a JSON object in the webhook response. DPS will then pass that data back in the **registrationState.payload** property in the [Register Device response](/rest/api/iot-dps/device/runtime-registration/register-device#registrationoperationstatus). For example, the following JSON shows the body of a successful response to register using TPM attestation.
3846

3947
```json
40-
{
41-
"iotHubHostName": "sample-iot-hub-1.azure-devices.net",
42-
"initialTwin": {
43-
"tags": {
44-
"tag1": true
45-
},
46-
"properties": {
47-
"desired": {
48-
"prop1": true
49-
}
50-
}
51-
},
52-
"payload": { A JSON object that contains the data returned by the webhook }
53-
}
48+
{
49+
"operationId":"5.316aac5bdc130deb.b1e02da8-xxxx-xxxx-xxxx-7ea7a6b7f550",
50+
"status":"assigned",
51+
"registrationState":{
52+
"registrationId":"my-tpm-device",
53+
"createdDateTimeUtc":"2022-08-31T22:02:50.5163352Z",
54+
"assignedHub":"sample-iot-hub-1.azure-devices.net",
55+
"deviceId":"my-tpm-device",
56+
"status":"assigned",
57+
"substatus":"initialAssignment",
58+
"lastUpdatedDateTimeUtc":"2022-08-31T22:02:50.7370676Z",
59+
"etag":"xxxx-etag-value-xxxx",
60+
"tpm": {"authenticationKey": "xxxx-encrypted-authentication-key-xxxxx"},
61+
"payload": { A JSON object that contains the data returned by the webhook }
62+
}
63+
}
5464
```
5565

56-
## SDK support
66+
The **payload** property must be a JSON object and can contain any data relevant to your IoT solution or scenario.
5767

58-
This feature is available in C, C#, JAVA and Node.js client SDKs. To learn more about the Azure IoT SDKs available for IoT Hub and the IoT Hub Device Provisioning service, see [Microsoft Azure IoT SDKs]( https://github.com/Azure/azure-iot-sdks).
68+
## SDK support
5969

60-
[IoT Plug and Play (PnP)](../iot-develop/overview-iot-plug-and-play.md) devices use the payload to send their model ID when they register with DPS. You can find examples of this usage in the PnP samples in the SDK or sample repositories. For example, [C# PnP thermostat](https://github.com/Azure/azure-iot-sdk-csharp/blob/main/iothub/device/samples/solutions/PnpDeviceSamples/Thermostat/Program.cs) or [Node.js PnP temperature controller](https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/pnp_temperature_controller.js).
70+
This feature is available in C, C#, JAVA and Node.js client SDKs. To learn more about the Azure IoT SDKs available for IoT Hub and IoT Hub Device Provisioning service, see [Microsoft Azure IoT SDKs]( https://github.com/Azure/azure-iot-sdks).
6171

6272
## IoT Edge support
6373

@@ -87,4 +97,6 @@ The payload file (in this case `/home/aziot/payload/json`) can contain any valid
8797

8898
## Next steps
8999

90-
* To learn how to provision devices using a custom allocation policy, see [How to use custom allocation policies](./how-to-use-custom-allocation-policies.md)
100+
* For an overview of custom allocation policies, see [Understand custom allocation policies](./concepts-custom-allocation.md)
101+
102+
* To learn how to provision devices using a custom allocation policy, see [Use custom allocation policies](./tutorial-custom-allocation-policies.md)

0 commit comments

Comments
 (0)