简体   繁体   中英

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

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?

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://docs.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://docs.microsoft.com/en-us/azure/iot-pnp/concepts-model-parser

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM