Azure IOT PnP Digital Twin API/SDK to retrieve Property, Command and Telemetry definitions for Device/Twin

150 views Asked by At

I am currently learning about Azure IOT Plug and Play and Digital Twins.

I am running the following Device Sample: Azure\IOT Plug and Play\azure-iot-samples-csharp\iot-hub\Samples\device\PnpDeviceSamples\Thermostat

and the corresponding Service Example: Azure\IOT Plug and Play\azure-iot-samples-csharp\iot-hub\Samples\service\PnpServiceSamples\Thermostat

To interact with the Thermostat: https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/samples/Thermostat.json

I would like to discover what Properties, Telemetry and Commands are available for a device/twin through an API/SDK based on the twin ID, However I notice that the Microsoft.Azure.Devices.Device and Microsoft.Azure.Devices.Shared.Twin classes only contain Property information and don't define Commands or Telemetry.

Microsoft.Azure.Devices.RegistryManager registryManager = _registryManager;

Microsoft.Azure.Devices.Device device = await registryManager.GetDeviceAsync(_digitalTwinId);

Microsoft.Azure.Devices.Shared.Twin twin = await _registryManager.GetTwinAsync(_digitalTwinId);

Can someone please tell me how I can get the Command and Telemetry definitions please?

1

There are 1 answers

0
Stefan Wick  MSFT On BEST ANSWER

To discover all the details of the device model dynamically in your application should do the following:

  1. identify the device's model-id
  2. resolve it to the model file from the repository
  3. parse the model file

See documentation here: https://learn.microsoft.com/en-us/azure/iot-pnp/concepts-model-discovery

To parse the model you can read the json directly, or use the model parser library to get a rich object model for the device model. See docs here: https://learn.microsoft.com/en-us/azure/iot-pnp/concepts-model-parser