Page 1 of 1

mDNS time to live

Posted: Mon Feb 25, 2019 3:24 pm
by balix53
Hello,

I am using the mDNS APIs however I don't see any option to set the TTL of my mDNS service. The service is visible on an Android smartphone with the application "Service Browser" but only for a brief period of time (I would say one second).

However I need my service to be always visible and I can't find a solution to do that. Is there any workaround to be able to set the TTL of an mDNS service ?

For now the only way I have found for the service to be always visible is to register and unregister it continuously.

Here is a code sample of how I set my mDNS service

Code: Select all

const char* name =  "hostname";
const char* service = "myservice";
const char* protocol = "tcp";

mdns_init();
mdns_hostname_set(name);
mdns_service_add(NULL, service, protocol, 80, NULL, 0);

Re: mDNS time to live

Posted: Mon Feb 25, 2019 4:16 pm
by ESP_cermak
Hi balix53,

adding a service should be enough to make it visible continuously, no need to setup TTL. (unless there is a bug)
which version of IDF are you using?

just checked with release 3.2 and android service browser can see the service, but have to follow the underscore convention

Code: Select all

const char* service = "_myservice";
const char* protocol = "_tcp";

Re: mDNS time to live

Posted: Fri Mar 08, 2019 9:03 am
by balix53
Indeed, the protocol must be prefixed with an underscore. I ended up using Bonjour Browser on Windows to see if my service was correctly registered and it works far better than Service Browser on Android. There should be no problem now.