Output of the function's updated data.

Matías Liñán García 25 Reputation points
2023-06-27T11:10:30.2233333+00:00

Hi, I am working with the IoT Hub with an external device and I am using the Azure IoT Explorer application to view the telemetry from my device.

Using eventgrid I have related my function to receive the data from my IoT Hub. But how could I see the data coming out of the function?

Because nothing is coming to the instance of digital twins.

Best regards.

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.
231 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,120 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 16,046 Reputation points
    2023-06-30T15:45:05.61+00:00

    Hi @Matías Liñán García Thank you for looking into this and sharing these updates. Here is a breakdown of what your function app code does. The error indicated that you are trying to access of property from the received event which does not exists. The following line of code could most likely have thrown that error.

    var angle = deviceMessage["body"]["roll"];

    This piece of code extracts the value set for the property "roll" from the event received to the event hub. For this to work as intended, the message event pushed from IoT Hub should have a property named roll in the message body. For example, here is a sample event I generated from my IoT Hub Device Simulator code referenced in Configure and run the simulation section {"Level_of_Material":67.7025913431787}. I have modified the telemetryDataPoint variable in the SendDeviceToCloudMessageAsync method of AzureIoTHub.cs class from the project as follows

    var telemetryDataPoint = new
    {
        Level_of_Material = currentTemperature
    };
    

    To capture this event, I should modify my function app line of code to var temperature = deviceMessage["body"]["Level_of_Material"];

    Here is how the Digital Twin update works.

    updateTwinData.AppendReplace("/Angle", angle.Value<double>());

    This line of code is used to patch the property on the Azure Digital Twin. Make sure that the twin you are targeting has a property named Angel defined in its model. In my example above, I should have a property named Level_of_Material" on my Digital Twin. Please find the below image showing the twin properties I have defined.

    enter image description here

    await client.UpdateDigitalTwinAsync(deviceId, updateTwinData);

    This event sends an update to the Digital Twin with the patch information. Notice that the deviceId we are using here is obtained from the message event delivered from IoT Hub. It could be possible that digital twin ID, which is $dtId, could be different from the device ID defined on IoT Hub. If it is different, make sure you provide the correct $dtId value here in the above code.

    If everything is configured correctly, your Digital Twin update should work as expected.

    Hope this helps! Please let us know if you have any additional questions or need further assistance on this.


    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.