How to update Azure Digital Twin using Python

----- 0 Reputation points

Hello Team,

I am trying to implement azure digital twin in python, I have gone through the documentation and executed the end-to-end twin with C sharp but I want to build it in python language, I have tried many examples but it doesn't seem to work. I can see the data received in azure iot explorer but the same doesn't appear in the log stream of the function app, I tried using both event grid trigger and http trigger but no luck, can you please assist me with an end-to-end example for azure digital twin using python.

Also when I use python to send telemetry data to the iot hub, the C sharp function app receives the telemetry data but the function never succeeds it just gives the message "Executing 'FunctionName' (Reason='EventGrid trigger fired at 2023-11-22T15:23:11.4201025+00:00', Id=aadbb1fd-8580-41d1-a3b3-9cfdd3801c1b)"

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,956 Reputation points

    Hello @----- Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    Based on the information you have provided in the question if your Azure function is not receiving any telemetry, it implies that the Azure function is not listening to the routing end point of IoT Hub where the data is being routing. When you monitor the events from Azure IoT Explorer, the data is typically monitored on the built in end point of IoT Hub by default. Please refer the below image.

    User's image

    Assuming you have followed the same steps from the guide Tutorial: Build out an end-to-end solution you would have configured your Azure function to listen to Event Grid. This is done by executing the below command from the section Connect the IoT hub to the Azure function

    az eventgrid event-subscription create --name <name-for-hub-event-subscription> --event-delivery-schema eventgridschema --source-resource-id /subscriptions/<your-subscription-ID>/resourceGroups/<your-resource-group>/providers/Microsoft.Devices/IotHubs/<your-IoT-hub> --included-event-types Microsoft.Devices.DeviceTelemetry --endpoint-type azurefunction --endpoint /subscriptions/<your-subscription-ID>/resourceGroups/<your-resource-group>/providers/Microsoft.Web/sites/<your-function-app>/functions/ProcessHubToDTEvents

    In addition to the above configurations, you would also need to grant your Azure function Azure Digital Twins Data Owner to provide write permissions. Please refer the section Assign access role for more details on this.

    You can find a complete code sample on the end-to-end implementation in Python from the following similar threads which have been addressed in the past.

    Hope this helps. If you still have any additional questions or need further assistance, please let us know in the comments below.

    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.