Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upnpcontrol] Send periodic keep alive #17976

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

digitaldan
Copy link
Contributor

This sends a periodic search packet to the remote upnp device as part of the thing's refresh cycle. This search request acts as a keep alive mechanism for devices that loose registration.
Fixes #16638

@digitaldan digitaldan requested a review from mherwege as a code owner December 24, 2024 21:31
@lsiepel lsiepel added the bug An unexpected problem or unintended behavior of an add-on label Dec 24, 2024
Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the single comment, LGTM.

Will wait for @mherwege to look at it before merging. Do you recommend to backport?

…hab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java

Co-authored-by: lsiepel <[email protected]>
Signed-off-by: Dan Cunningham <[email protected]>
@digitaldan
Copy link
Contributor Author

Thanks, i would suggest backporting this one.

@mherwege
Copy link
Contributor

mherwege commented Dec 25, 2024

I am a bit in doubt about this solution. The binding so far refrained from explicit M-SEARCH calls and relied on the upnp service for this. And you state this issue also appears with Sonos. Would it then not be better to solve this in the transport, like here: https://github.com/openhab/openhab-core/blob/1f9ba2b0eea9daf70515cd36b53c3fe1d2f1e54d/bundles/org.openhab.core.io.transport.upnp/src/main/java/org/openhab/core/io/transport/upnp/internal/UpnpIOServiceImpl.java#L434. Maybe @wborn has an opinion on this.
I am still OK to solve it in the binding if the other options don’t work out, but there are 2 underlying layers (upnp transport and service) that in my opinion should be responsible for the stability of the connection.

@digitaldan
Copy link
Contributor Author

I'm not familiar at all with the UPNP backend, but i'll try taking a look, may take a little bit.

@digitaldan
Copy link
Contributor Author

@mherwege just looking at the code you referenced and how its called from this binding, what does "GetCurrentConnectionIDs" mean in this code?

https://github.com/digitaldan/openhab-addons/blob/06b361c13904f6ea12e42ff594a23ed0df702314/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandler.java#L620

@mherwege
Copy link
Contributor

mherwege commented Dec 28, 2024

This is a standard uPnP action that is always implemented on all of the different services involved with media. It should always return something. So that’s why it has been chosen for the polling. If it fails, something is wrong with the connection. As this polling is done anyway, it consider this a potential place to add the M-SEARCH code.

@andrewfg
Copy link
Contributor

@digitaldan as mentioned in openhab/openhab-core#4527 my proposal is to apply a (temporary) fix in the binding that does NOT rely on any eventual change in OH core.

Furthermore -- instead of your current code -- I would suggest to try one or more of the following code lines either a) one time only during your handler factory initialization, or b) periodically analogous to what you are doing in your current code.

upnpService.getRegistry().addListener(this); 

// and/or
upnpService.getControlPoint().search(); 

// and/or
upnpService.getControlPoint().search(new RootDeviceHeader()); 

@digitaldan
Copy link
Contributor Author

Furthermore -- instead of your current code

I can do that, my only thought with the current code was to target a specific device vs triggering a search request for any device jUPnP might care about which would cause some noise for other bindings that may be listening for (new) device activity (like Sonos?) Was trying to be nice and keep the collateral noise to just devices used in the binding.

If this is not a problem (and i don't think it would be) , then i'm happy to switch to using your suggestion ;-)

@andrewfg
Copy link
Contributor

andrewfg commented Jan 1, 2025

@digitaldan to make your search more specific you could use the following. And instead of searching every one minute, you could perhaps check the device.getIdentity().getMaxAgeSeconds() value and send even fewer requests. (The max age expiry is usually between 5 and 30 minutes).

upnpService.getControlPoint().search(new UDNHeader(udn));

@digitaldan
Copy link
Contributor Author

perhaps check the device.getIdentity().getMaxAgeSeconds()

I like that idea, i'll look into it.

@andrewfg
Copy link
Contributor

andrewfg commented Jan 2, 2025

I like that idea, i'll look into it.

@digitaldan for the time being you could borrow my code for this addon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[upnpcontrol] Device goes offline with device not registered error
4 participants