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.

[Question] [Twin] Update reported properties after reconnection.

See original GitHub issue

Context

  • OS and version used: Windows 10
  • Python version: Python 2.7.17
  • pip version: pip 20.0.2
  • SDK version: V2 with threads/synchronous applications.

Description of the issue:

Hi,

I have a question regarding the management of the versioning between the desired properties and the reported properties. Let’s assume that while my device/module was disconnected, I made more than one change to the desired properties. When my device/module reconnects, the listener for the patches will not see any changes (as described here). So, to change the reported properties I need to get all the document (using the get_twin() method, for example) and check the $version field.

But the problem is that if I made more than one change I cannot change the $version directly to equal them (i.e. desired: $version 6, reported: $version 2). More than that, if it’s about adding/removing fields there’s no problem: I can check then individually; but if I made 6 changes to one field, I cannot see all the other 5 modifications to change incrementally on my reported properties. So how can I manage properties with reconnection properly? Is there any code sample for this?

Thanks in advance.

AB#7366701

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
elhortoncommented, Jul 14, 2020

Thanks @RickBadKan for raising this issue. Since we are tracking this as a feature request in issue #599 , we are going to close this issue. We appreciate you helping make our Python SDK better!

1reaction
BertKleeweincommented, Jun 18, 2020

@RickBadKan - right now, the only way I know to detect if the twin version has changed is to re-fetch the full twin and compare the $version values. If the version has changed, the only way to know what has changed is to look through it property-by-property. Another alternative is to use a json patch library such as https://pypi.org/project/jsonpatch/ to calculate the diff. I haven’t looked at this library in detail, but I assume that it properly handles setting properties to None if they are deleted in the second object.

Regarding the extra bandwidth consumed by automatically fetching the twin on reconnect, I’ve opened #599 to suggest a new feature that turns this off.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understand Azure IoT Hub device twins - Microsoft Learn
This operation returns the device twin document, including tags and desired and reported system properties. Partially update device twin. This ...
Read more >
How to update Azure Device Twin desired and reported ...
I want to pass this data to the device twin, so that even if the device is offline, as soon as it comes...
Read more >
AWS IoT Device Shadow service
Apps specify the desired states of device properties by updating the desired object. reported. Devices report their current state in the reported object....
Read more >
Azure IoT Hub - Routing device twin changes deep dive
For reported property changes, we must simulate the device so I have ... az iot hub device-twin update --hub-name $hub_name -d $device_id ...
Read more >
[IoT Home Project] Part 7 - Read/Write data to device twin
To update reported properties of device twin we need to create an object with the values that we want to report. The good...
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