How to get DTDL models from backend application

Alex Fang 230 Reputation points
2023-08-21T22:24:08.2733333+00:00

I am working on an application where I wish to access the DTDL model that I designed. The purpose of this is so that I can parse through the model in the application and be able to dynamically format my pages. This would be seen in the units or types of telemetry data that I display in my application or in the possible types of configurations or direct methods that I can display on my application for users to control their devices.

I do not believe that the exact models are shown in the data obtained with get_digital_twin.js. I think this would be the way to achieve my goal. How would I go about doing this?

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
385 questions
Azure Digital Twins
Azure Digital Twins
An Azure platform that is used to create digital representations of real-world things, places, business processes, and people.
221 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,136 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde 29,616 Reputation points MVP
    2023-08-21T22:59:37.0933333+00:00

    Hello @Alex Fang,

    The name 'digital twin' can be a bit confusing here.

    If you want to use Azure Digital Twins, you need to work with the Azure Digital Twins service.

    Here, the 'digital twin' is the ModelID as seen in the IoT Hub device DeviceTwin:

    // Get digital twin and retrieve the modelId from it
    const digitalTwin = await digitalTwinClient.getDigitalTwin(deviceId);
    

    This ModelId is a reference to registered DTDL models.

    If you have the reference, you can get the actual model at:

    https://devicemodels.azure.com/

    Check out this example:

    https://devicemodels.azure.com/dtmi/azure/devicemanagement/deviceinformation-1.json

    Now you can parse the model and check out units etc.

    Check out the blog post for more details.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


1 additional answer

Sort by: Most helpful
  1. Dom 1,556 Reputation points Microsoft Employee
    2023-08-29T15:47:07.0333333+00:00

    The official DTDL parser was updated earlier this year - you can find the latest version of the parser, samples and tutorials here: https://github.com/digitaltwinconsortium/DTDLParser

    0 comments No comments