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.
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.