azureazure-iot-centralazure-digital-twins

How to send Azure IoT Central data to Azure Digital Twin - Data ingestion workflow


for a demo, I would like to send data from Azure IoT Central to Azure Digital Twins similar to what I was able to successfully implement in the following scenario described here (https://learn.microsoft.com/en-us/azure/digital-twins/how-to-ingest-iot-hub-data).

In the above description, an Azure Function in C# is used, which is bound to an IoT Hub via an Event Grid Trigger.

Azure IoT Central does not have an event grid connection and the comments from here (https://learn.microsoft.com/en-us/answers/questions/266039/how-to-trigger-an-event-grid-from-an-iot-central-r.html) do not really help me.

Isn't there a simple and more feasible way to connect the two?

Would the following be possible?

  1. IoT Central receives the data from a device and forwards it as an export to a webhook.

  2. The webhook is an Azure function that converts the data from the device into the format of the digital twin and then forwards it to it.

Would this be a possible way or what would be the best way to do this?

I would really appreciate any tips, experiences, comments and code examples.

Best regards init5


Solution

  • For your solution can be used a recently added a new feature of the Azure IoT Central such as Data transformation.

    The Data transformation allows to create your custom payload for exporting to the specific destination, in your case via the webhook endpoint.

    The following is an example to send the telemetry data to the Azure Event Grid custom topic:

    Destination:

    enter image description here

    Data transformation:

    {
      specversion:"1.0",
      id:.applicationId,
      source: .device.id,
      subject:"/myapp/vehicles/motorcycles",
      type:"recordInserted",
      time:.enqueuedTime,
      dataschema:"#",
      data:{
        timestamp: (now | strflocaltime("%Y-%m-%dT%H:%M:%S.%fZ") | tostring),
        telemetry: .telemetry | map({ key: .name, value: .value }) | from_entries,
        properties: .messageProperties
      }
    }
    

    Note, that the payload is for CloudEvents schema, but those mandatory properties can be moved to the headers and explicitly populated (the IoT Central didn't have capability to handle their value as an expression)

    ce-id
    ce-source
    ce-specversion
    ce-type
    

    The same way you can make a data transformation for the destination endpoint Azure Digital Twin based on the document here.