title | description | author | ms.author | ms.date | ms.topic | ms.service | services |
---|---|---|---|---|---|---|---|
How to transfer a payload between device and Azure Device Provisioning Service |
This document describes how to transfer a payload between device and Device Provisioning Service (DPS) |
kgremban |
kgremban |
12/03/2021 |
conceptual |
iot-dps |
iot-dps |
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.
This feature can be used as an enhancement for custom allocation. 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. 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.
When your device is sending a register device call to DPS, The register call can be enhanced to take other fields in the body. The body looks like the following:
{
"registrationId": "mydevice",
"tpm": {
"endorsementKey": "stuff",
"storageRootKey": "things"
},
"payload": { A JSON object that contains your additional data }
}
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.
{
"iotHubHostName": "sample-iot-hub-1.azure-devices.net",
"initialTwin": {
"tags": {
"tag1": true
},
"properties": {
"desired": {
"prop1": true
}
}
},
"payload": { A JSON object that contains the data returned by the webhook }
}
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.
IoT Plug and Play (PnP) 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 or Node.js PnP temperature controller.
- To learn how to provision devices using a custom allocation policy, see How to use custom allocation policies