question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to get Twin Patch Handler to work

See original GitHub issue

Context

  • 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:

  1. Go to Portal
  2. Open Device + Module
  3. Edit the Module Identity Twin + Save

OR

  1. Go to VSCode IoTHub
  2. Right Click module -> Edit Module Twin
  3. 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:closed
  • Created 3 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
cartertinneycommented, May 11, 2021

We have been able to reproduce the issue and are now looking for solutions.

0reactions
cartertinneycommented, Jun 17, 2021

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found