Telemetry Data from IOT hub not pushing to azure function and not reflecting to Digital Twin?

Addanki, Srikar 0 Reputation points
2023-04-28T06:01:57.1533333+00:00

I've been trying to replicate -> https://learn.microsoft.com/en-us/azure/digital-twins/tutorial-end-to-end using my own variables, the telemetry data is pushing to IOT hub but from there on its not getting pushed to the functions eventually my digital twin is not getting updated. I rechecked the variables and naming appropriately, still not getting where the root cause is.

Telemetry data which Im generating:

User's image

Value not getting updated for the device twin, only the static value showing up.

User's image

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.
228 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
374 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 14,676 Reputation points Microsoft Employee
    2023-04-28T15:51:35.2566667+00:00

    Hi @Addanki, Srikar There are couple of places in the Azure function Apps where the patching of Azure Digital Twins is done to the property.

    • Line 50 of ProcessHubToDTEvents.cs file. Please find the line of the command that comes default with the App
    updateTwinData.AppendReplace("/Temperature", temperature.Value<double>());
    
    • Line 73 of ProcessDTRoutedData.cs file. Here is the line of code
    if (propertyPath.Equals("/Temperature"))
    

    This if condition is specifically looking for a match on Temperature property and only then updates the Digital twin property.

    Can you confirm if you have updated the function in both places to replace Temperature with the property you have defined.

    Please note that these properties are case sensitive and should be used the same way you have defined in your Model.json file

    • Inspect the line 44 of ProcessHubToDTEvents.cs file which looks up for the telemetry data pushed from IoTHub and retrieves the property that needs to be patched. The property should be the same as what is defined in line 56 of AzureIoTHub.cs file. Please refer the below line of code
    var temperature = deviceMessage["body"]["testpropupdate"];
    
    • Line 43 of ProcessHubToDTEvents.cs class reads the Digital Twin ID to which the JSON patch updates need to be applied for. If you follow the step Register the simulated device with IoT Hub in the tutorial as it is, it will create a device with ID thermostat67 which is different from the $dtID of the digital twin. The Azure function in file ProcessHubToDTEvents.cs looks for the same digital twin ID and tries to apply a patch on line 51. Make sure to create a device with ID same as the $dtId of the digital twin.

    Once you have function App code modified to reflect the correct property, please make sure to publish the functions again to Azure portal using Azure CLI command az functionapp deployment source config-zip --resource-group <resource-group> --name <name-of-your-function-app> --src "<full-path-to-publish.zip>" so that you have updated code.

    After making the above changes, you can see that the property with custom name gets updated as expected on the Azure Digital Twin. Please refer the below images.

    Screenshot_138

    Screenshot_139

    Please let us know if you still face issues with the property updates after making the above changes.


    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.