Digital twin relationship effecting data receiving

Juanhe Shen 50 Reputation points
2023-11-21T23:23:52.1166667+00:00

Greetings:

I ran into a little problem with Azure Digital Twin Explorer. So I can get the data sent to a specific twin, however, things change a little bit when I am trying to send the data to the twin that is in a relationship with a another twin. So the twin that can receive data, I will call it the child twin, the parent twin is not yet active or not ready to use, thus its value is empty. The log stream of my function tells me the system cannot find the twin with the dtid, but the twin is there, but just in relationship with a nonactive twin. The twin that sits by itself is fine, they can receive data. I tried, and it turns out only the twin with the relationship cannot receive. I might be missing something or did something wrong. If someone can help me, that would be great.

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.
224 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,966 Reputation points
    2023-11-29T00:05:37.7166667+00:00

    Hi @Juanhe Shen I understand that we are still waiting on getting more feedback on this issue. I am providing the below response outlining the general steps to be followed for updating a digital twin to help other community members looking running into a similar issue.

    You can find the detailed simulation sample on how to update a digital twin from IoT Hub data on this link Tutorial: Build out an end-to-end solution. The tutorial walks you through the steps of updating a digital twin from an Auzre function using .Net DigitalTwinsClient Class. The class offers a method UpdateDigitalTwinAsync which accepts the Digital twin Id that needs to be updated and the JSON patch document contains the overwritten values. Below is a sample from Azure Event Grid function which picks data from Event Grid and pushes a telemetry value to a property of Digital twin.

    try
    {
    log.LogInformation(eventGridEvent.Data.ToString());
    JObject deviceMessage = (JObject)JsonConvert.DeserializeObject(eventGridEvent.Data.ToString());
    string deviceId = (string)deviceMessage["systemProperties"]["iothub-connection-device-id"];
    var temperature = deviceMessage["body"]["Level_of_Material"];
    
    log.LogInformation($"Device:{deviceId} Level_of_Material is:{temperature}");
    
    //Update twin using device temperature
    var updateTwinData = new JsonPatchDocument();
    updateTwinData.AppendReplace("/Level_of_Material", temperature.Value<double>());
    await client.UpdateDigitalTwinAsync("deviceId", updateTwinData);
    }
    catch(Exception ex){
    Console.WriteLine($"Error : {ex.Message}");
    }
    

    Please make sure you are targeting the correct device Id and property name of the Digital Twin for the update to succeed.

    Once you decide to go with the updating a digital twin with the relationship and still experience issues, please feel free to tag us in the comments below and we would be happy to assist you.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments