dominicusmento / CSharpTradFriLibrary

This is a .NET Standard (2.0) library to communicate with the IKEA Home (Tradfri) ZigBee-based Gateway.
GNU General Public License v3.0
37 stars 20 forks source link

Observing a device only works for a short time #17

Closed scheelings closed 5 years ago

scheelings commented 5 years ago

I am using the ObserveDevice method on the DeviceController instance to observe updates on a device. When I immediately use my remote control to toggle the lights on/off, I get a notification through the observer. But when I wait for some time (2 minutes) the notifications are not being received anymore.

Is there a way to observe devices for a longer time?

coriumalpha commented 5 years ago

Hi scheelings, try to publish the project and then executing it. If you use the VS debugger the Windows Firewall will cause some unexpected behaviours as described here #14 Using this method enables you to observe the device up until 4 hours or so (I didn't measure it precisely), after 4 hours it stops listening, I'm not sure about why but I think that it may be a Garbage Collector related issue.

dann-it commented 5 years ago

Hi @coriumalpha, I already tried this, but still within 2 minutes I do not get any updates anymore. So I have created a timer which will call the Observe method again every minute. This way it will work, but I do not know if this can cause other issues.

coriumalpha commented 5 years ago

I will recommend you to analyze the life cycle of your observer object because of the Garbage Collection thing, it may be disposing your object (or some property of it) too early in its life cycle, I'm not used to work with GC so I won't be able to further help you in that direction. As far as I tested, the Tradfri gateway still makes requests when the observer object stopps listening (check network requests with Wireshark and notice that the update requests are still being sent to the observer but the observer doesn't take care of thoose, so it is a CoAP Observer issue). I won't be able to replicate this issue because I stopped using the Tradfri gateway in favor of Philips Hue Bridge because of the closeness of the Tradfri Gateway, so it is now collecting dust in a drawer.

I can give you access to a test project that I used to test the observer thing. It works as spected for the first 4 hours. Just lemme know.

scheelings commented 5 years ago

Hi @coriumalpha, I posted a reply here days ago, but it is not visible anymore. I checked the GC but the objects are not collected at all, so that should not be the issue. I also checked Wireshark and indeed the messages are being sent by the gateway, but not received by the Observer objects (after about 1 minute).

So, if you could share your test project, that would be great!

dominicusmento commented 5 years ago

Observe definitely works longer than 2 minutes when app is published and added to firewall exceptions like @coriumalpha said so I'm closing this issue (I've tested for half an hour).