Not able to get Twin Patch Handler to work
See original GitHub issueContext
- OS and version used: Windows 10
- Python version: 3.8.6
- pip version: 21.0.1
- list of installed packages: N/A (will post if required anyways)
- cloned repo: N/A
Description of the issue
When trying to work with the module_client.on_twin_desired_properties_patch_received
I am expecting my method to be executed when the Twin for my module gets updated and my print
call being executed.
⚠ I am utilizing the Simulator to test this! I am not 100% sure this is supported but could not find documentation stating that this is not supported.
The way I test Twin updates:
- Go to Portal
- Open Device + Module
- Edit the
Module Identity Twin
+ Save
OR
- Go to VSCode IoTHub
- Right Click module -> Edit Module Twin
- Edit Twin + Click
Update Module Twin
in the left top
Code sample exhibiting the issue
import time
import os
import sys
import asyncio
from six.moves import input
import threading
from azure.iot.device.aio import IoTHubModuleClient
from azure.iot.device import Message
import random
async def main():
try:
print("IoT Hub Client for Python")
# The client object is used to interact with your Azure IoT hub.
module_client = IoTHubModuleClient.create_from_edge_environment()
# connect the client.
await module_client.connect()
async def main_loop(module_client):
while True:
print("Waiting for commands")
await asyncio.sleep(1)
def twin_patch_handler(patch):
print("the data in the desired properties patch was: {}".format(patch))
module_client.on_twin_desired_properties_patch_received = twin_patch_handler
print("The sample is now waiting for messages. ")
await main_loop(module_client)
# Finally, disconnect
await module_client.disconnect()
except Exception as e:
print("Unexpected error %s " % e)
raise
if __name__ == "__main__":
asyncio.run(main())
Thanks for helping in advance! Let me know if anything else is required from my side.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
Tutorial - Synchronize device state from Azure IoT Hub
This tutorial shows you how to use desired and reported properties to synchronize state information. Diagram of device twins on the device and ......
Read more >Python virtual device handle changed event from azure IoT hub
The event fires and prints out the new device twin properties (Eventully, this should call some other code, to change the mode of...
Read more >Azure IoT DeviceClient SDK Python demonstration, the basics
So, get a (free) Azure Subscription, install Python and Visual Studio code so you can start ... define behavior for receiving a twin...
Read more >Azure IoT Hub Connector — Device Twin Support
Data is structured like JSON, but no array values are allowed. Key values are limited to 64 UTF-8 bytes and cannot contain periods,...
Read more >Develop Azure Digital Twins (ADT) solutions
With Azure Digital Twins, it is possible to create and interact with live models ... the Azure Digital Twins instance, otherwise you will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We have been able to reproduce the issue and are now looking for solutions.
I’m going to close this issue now due to inactivity. If the issue persists, please open a new GitHub issue and we will be happy to assist.