Terence
Terence

Reputation: 1

Connecting Azure Digital Twin update to IoT Hub

I am currently working on a part of a project that needs me to somehow send changes in digital twin property to IoT Hub and then to Node Red. I have seen a few sample projects that are similar but most I have encountered were either sending telemetry from Hub to ADT or updating parent DT from another ADT.

For context, the end goal of this part of the project is to be able to

  1. send inputs from a unity project to ADT where the sensor for e.g "SF1, SF2..."
  2. ADT sends updates to sensor to IoT Hub
  3. IoT Hub will then push to Node Red for further processing. However for now due to some situation, we are ignoring the unity project for now and just focusing on getting the ADT->IoT Hub pipelines up first by simulating the change using either a device simulator or manual change.

I tried following the tutorial ''connect an end-to-end solution'' up to the point where update to the parent digital twin was made but the connection from twin-twin is not the one I need. The other tutorial I was following on the Microsoft page was about "integrate with azure signalR service - Azure Digital Twin" but it links to an external webpage instead of an azure service. I am currently trying to receive a digital twin update using eventgrid trigger with azure function to be sent to IoT hub and finally to mqtt-in node-red for further processing.

Need advice on whether I am heading in the right direction for my goals or do I need to use other services and if so could you advise on which?

Upvotes: 0

Views: 120

Answers (1)

Sampath
Sampath

Reputation: 3639

I referred to the documentation for instructions on ingesting IoT Hub telemetry into Azure Digital Twins.

Below are the steps in the documentation:

  • Create a new or use an existing IoT Hub and Azure Digital Twins instance.

  • Upload a thermostat model to Azure Digital Twins, defining properties such as Temperature.

{
    "@id": "dtmi:contosocom:DigitalTwins:Thermostat;1",
    "@type": "Interface",
    "@context": "dtmi:dtdl:context;3",
    "contents": [
      {
        "@type": "Property",
        "name": "Temperature",
        "schema": "double"
      }
    ]
}

enter image description here

  • Create an Azure Function to access Azure Digital Twins and update twins based on IoT device telemetry events in Azure. Use this git to receive events.

  • Run the simulated IoT data to send mock device telemetry data to your IoT Hub.

private const string iotHubConnectionString = "<your-hub-connection-string>";
//...
private const string deviceConnectionString = "<your-device-connection-string>";

enter image description here

  • While running, you can view the thermostat digital twin data using az dt twin query.

enter image description here

Additionally, refer to this repository for the Azure IoT Digital Twin Device Bridge module for Node-RED. For more guidance on connecting Node-RED to Azure IoT Hub using MQTT nodes, check out this tutorial.

Upvotes: 0

Related Questions