MDNS Advertisements from OH

Is there a mechanism already existing in OH to make mdns advertisements? In my specific use case I have a developer mode on the binding to help decipher the protocol(s). Right now I use AVAHI on the host to make the advertisements which is not optimal. I’d prefer to make the advertisements directly from OH when the mode is active.

Have a look at the code that openHAB uses to announce the REST APIs using mDNS in MDNSAnnouncer.java. It’s using the MDNSService.

Awesome! I’ll check that out. Thank you!

1 Like

I’ve looked through it a bit and it seems to make sense that there is a central MDNSService run by OH. It looks like I need to define ServiceDescription getDefaultServiceDescription() and then pass it as mdnsService.registerService(getDefaultServiceDescription()) or unregisterService().

Here’s my question, how, from a binding, do I get to the central registered MDNSService to define mdnsService? In MDNSAnnouncer there is a public void setMDNSService(MDNSService mdnsService) which handles this. A code search does not show me where we are having that set from the other side though (as in, I can’t find the specific part of the overall code which sends that).

EDIT: I’ve setup a branch here to test this…

You can get it injected in your AndroidTVHandlerFactory:

    @Activate
    public AndroidTVHandlerFactory(
            final @Reference AndroidTVDynamicCommandDescriptionProvider commandDescriptionProvider,
            final @Reference MDNSService mdnsService,
            final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider) {
        this.commandDescriptionProvider = commandDescriptionProvider;
        this.mdnsService = mdnsService;
        this.translationProvider = new AndroidTVTranslationProvider(i18nProvider, localeProvider);
    }

Then you inject it into the AndroidTVHandler via its constructor and similary inject it via the constructor into the GoogleTVConnectionManager.

Perfect. Didn’t realize I could pull that up there. Thanks!

1 Like

That worked great. Is there a list of the things that can be pulled in somewhere? For example, the last piece of this is for me to pull the IP of the OH server in so I can include it in the advertisement.

Having an issue with the advertisement. I believe it’s because my OH is in a docker (which is something I need to account for on this). Notice there are two advertisements coming out, one with the docker ip (172.x) and one with the docker host ip (10.x). My networking on the docker is in host mode so I normally don’t have to forward any ports to it and mdns does work when OH is the client.

An actual device:

2023-07-16 20:34:41.003 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \00
2023-07-16 20:34:41.004 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: [SHIELD] Living Room._androidtvremote2._tcp.local.
2023-07-16 20:34:41.012 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/10.255.0.20] (1)
2023-07-16 20:34:41.012 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 10.255.0.20
2023-07-16 20:34:41.013 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service property macAddress: null

When sent from AVAHI

2023-07-16 20:38:01.961 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \024bt=1C:69:7A:AA:AA:46
2023-07-16 20:38:01.961 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: SHIM._androidtvremote2._tcp.local.
2023-07-16 20:38:01.961 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/10.255.0.99] (1)
2023-07-16 20:38:01.961 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 10.255.0.99
2023-07-16 20:38:01.961 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service property macAddress: 1C:69:7A:AA:AA:46

What OH sends out:

2023-07-16 20:34:43.514 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \00
2023-07-16 20:34:43.514 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: OH GoogleTV SHIM._androidtvremote2._tcp.local.
2023-07-16 20:34:43.515 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/10.255.0.99] (1)
2023-07-16 20:34:43.515 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 10.255.0.99
2023-07-16 20:34:43.515 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service property macAddress: null

2023-07-16 20:34:43.516 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \024bt=1C:69:7A:AB:CD:EF
2023-07-16 20:34:43.516 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: OH GoogleTV SHIM._androidtvremote2._tcp.local.
2023-07-16 20:34:43.517 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/10.255.0.99] (1)
2023-07-16 20:34:43.517 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 10.255.0.99
2023-07-16 20:34:43.518 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service property macAddress: 1C:69:7A:AB:CD:EF

2023-07-16 20:34:43.587 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \00
2023-07-16 20:34:43.588 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: OH GoogleTV SHIM._androidtvremote2._tcp.local.
2023-07-16 20:34:43.588 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/172.17.0.1] (1)
2023-07-16 20:34:43.589 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 172.17.0.1
2023-07-16 20:34:43.589 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service property macAddress: null

2023-07-16 20:34:43.590 [DEBUG] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS discovery notified of GoogleTV mDNS service: \024bt=1C:69:7A:AB:CD:EF
2023-07-16 20:34:43.590 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service qualifiedName: OH GoogleTV SHIM._androidtvremote2._tcp.local.
2023-07-16 20:34:43.590 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service ipAddresses: [/172.17.0.1] (1)
2023-07-16 20:34:43.591 [TRACE] [scovery.GoogleTVDiscoveryParticipant] - GoogleTV mDNS service selected ipAddress: 172.17.0.1

How do I block the docker IP from going out?

I don’t think that is currently possible.

When MDNSServiceImpl#registerService is called it delegates the service registration to the localClient.
If you look at that implementation it registers the service for all instances.
An instance is created for each network interface when the client is started.

Maybe enabling this “Advanced” setting in the “Network Settings” helps :slight_smile:

Sorry I should have linked the PR over. I think the doubling may be a reflection from the docker host itself, unsure.

What I did notice (see PR) is that the AVAHI advertisements have an A-record and the OH ones do not.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.