Skip to content

MDNS.addService not working #962

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

Closed
natcl opened this issue Jan 2, 2018 · 27 comments
Closed

MDNS.addService not working #962

natcl opened this issue Jan 2, 2018 · 27 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@natcl
Copy link

natcl commented Jan 2, 2018

Please fill the info fields, it helps to get you faster support ;)

Hardware:

Board: Adafruit ESP32 Feather
Core Installation/update date:
IDE name: Arduino 1.8.5 on MacOS
Flash Frequency: ?80Mhz?
Upload Speed:

Description:

Using the mDNS_Web_Server example sketch, I can't get the addService method to work. The sketch runs fine, I can access my ESP32 using the esp32.local URL but it doesn't get advertised on the network when checking with different mdns browsers. Similar code works with the esp8266. Also browsing services seems to work.

@baggior
Copy link
Contributor

baggior commented Feb 3, 2018

I confirm this problem even with a generic ESP32 board
board = esp32dev

@baggior
Copy link
Contributor

baggior commented Feb 3, 2018

#387

@beegee-tokyo
Copy link
Contributor

beegee-tokyo commented Feb 4, 2018

Works without problems for me, but I am not using MDNS.begin, instead I am using ArduinoOTA to start the mDNS service.

ArduinoOTA.setHostname("ESP32-Test-2481CE9C");
ArduinoOTA.begin();
// addd some more service text
MDNS.addServiceTxt("_arduino", "_tcp", "service", "MHC");
MDNS.addServiceTxt("_arduino", "_tcp", "type", "TestBoard");
MDNS.addServiceTxt("_arduino", "_tcp", "id", "ESP32-Test");

Result of Service Browser on my Android tablet:
screenshot_2018-02-04-16-56-39

I am using Visual Studio Code/PlatformIO.
Platform Espressif32 (Stage) Version 1392c2a

@natcl
Copy link
Author

natcl commented Feb 4, 2018

But that’s to advertize the Arduino service. If you want to advertize a generic service (like OSC over UDP) it doesn’t work.

@baggior
Copy link
Contributor

baggior commented Feb 5, 2018

No the service is not shown even in Service Browser forAndroid
The same code works for ESP8266 but not for ESP32
I did

WiFi.setHostname(..)
MDNS.begin(..)
MDNS.addService(..)

@beegee-tokyo
Copy link
Contributor

Maybe it works for me, because I am using the "staging" version, but when I do

	WiFi.setHostname("ESP32-Test-mDNS");
	MDNS.begin("ESP32-Test-mDNS");
	MDNS.addService("_osc","_udp",4500);
	MDNS.addServiceTxt("_osc","_udp","does","it");
	MDNS.addServiceTxt("_osc","_udp","work","?");
	MDNS.addServiceTxt("_osc","_udp","yes","!");

The result in Android service browser is
screenshot_2018-02-05-09-13-15

I see that you are saying you use MDNS.begin();. That throws a compilation error for me. MDNS.begin() requires a parameter which is the hostName.

src\ota.cpp: In function 'void activateOTA(const char*, const char*)':
src\ota.cpp:126:13: error: no matching function for call to 'MDNSResponder::begin()'
MDNS.begin();
^
In file included from src\setup.h:20:0,
from src\ota.cpp:1:
C:\users\beegee\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS\src/ESPmDNS.h:57:8: note: candidate: bool MDNSResponder::begin(const char*)
bool begin(const char* hostName);
^
C:\users\beegee\.platformio\packages\framework-arduinoespressif32\libraries\ESPmDNS\src/ESPmDNS.h:57:8: note:   candidate expects 1 argument, 0 provided
*** [.pioenvs\esp32dev\src\ota.o] Error 1

And again, I am on the latest staging version:
platform

@beegee-tokyo
Copy link
Contributor

Ok, I started comparing the ESPmDNS.cpp (ESP32) with the ESP8266mDNS.cpp (ESP8266) and found some interesting differences.
On the ESP32 version you have to make sure

  • that the service name is lower case
  • that the service name and protocol starts with an '_' e.g. '_udp'

On the ESP8266 version the library takes care of

  • copying service name to lower case
  • adding the '_' in front if necessary.

So maybe try

  • to change your service name into all lower case and add the '_' in front
  • to change your protocol name into all lower case and add the '_' in front

It nether bothered me because I did the same all my ESP8266 projects and ESP32 projects already, so I never saw the problem.

@me-no-dev - Maybe ESPmDNS needs some update to be 100% compatible with the ESP8266 version.

@xinort
Copy link

xinort commented Feb 5, 2018

Doesn't work for me either. And hasn't for quite a while.

Edit: I changed "tcp" to "_tcp" and it works!

@beegee-tokyo
Copy link
Contributor

I tried it on

  • Arduino IDE with the lastest master version of the platform
  • PlatformIO/Visual Studio Code with the lastest master version of the platform
  • PlatformIO/Visual Studio Code with the lastest staging version of the platform

I tried it with the ESP32 example codes

  • mDNS_Web_Server.ino
  • mDNS-SD_Extended.ino

In the example codes I only made the changes from "http", "tcp" to "_http", "_tcp" to get it working.

One thing I found out is that after flashing, the mDNS advertise sometimes couldn't be found immediately. Then I had to do a hard reset (push reset button or power off/on cycle). After a hard reset it worked always.

Can you give me a code excerpt that shows the initialization and adding of services?

@baggior
Copy link
Contributor

baggior commented Feb 5, 2018

@beegee-tokyo I've added the "_" prefix to service and protocol and now it works..
The service is published and visible in Android service browser..

TO BE DOCUMENTED..

but the query method doesn't work since MDNS.query cannot find any result..( with or without the prefix)

Anyway there is a bug or a serious inconsistency, since in the query method code the "_" prefix is added anyway while int the addService method the prefix is required to be provided in the input parameter..

@beegee-tokyo
Copy link
Contributor

beegee-tokyo commented Feb 5, 2018

Anyway there is a bug or a serious inconsistency, since in the query method code the "_" prefix is added anyway while int the addService method the prefix is required to be provided in the input parameter..

Saw this as well. Inconsistent and in general the ESP8266 and ESP32 mDNS should work the same.

But happy I could at least help with the advertising.
I tried the query example mDNS-SD_Extended.ino and it worked for me. It found all mDNS services in my system. Will copy my working code into a Gist and post the link tomorrow.

@baggior
Copy link
Contributor

baggior commented Feb 5, 2018

@beegee-tokyo so can you fix that all?
commit and open a pull request?

@beegee-tokyo
Copy link
Contributor

Will try in the next days.

@beegee-tokyo
Copy link
Contributor

@baggior pull request sent, now it is up to @me-no-dev to merge it.

@baggior
Copy link
Contributor

baggior commented Feb 6, 2018

@beegee-tokyo thank you anyway the query() method doesnt works for me with or without '_'
I'm using staging too

can you please check also this bug and try to fix it in the same PR #1085?

here's my code gist
https://gist.github.com/baggior/f952b2884b1733b5248fb5f95234d63e

the output is always "no services found"

@beegee-tokyo
Copy link
Contributor

@baggior I successfully tested the query with "standard" services like http, workstation or SSH. Didn't try it with UDP port and "special" service.
Will setup a device as _osc._udp and see what I can do.
Btw. query() does not find a mDNS advertisement registered on the same device, only other devices.

@baggior
Copy link
Contributor

baggior commented Feb 6, 2018

Really
my test was to find the same device so I have to make another test ..

please add a note in the source as a comment about that then...

@beegee-tokyo
Copy link
Contributor

I think that is intended behavior. I setup an _osc._udp mDNS service on an ESP8266 and an ESP32.
Then I started a query on both devices.
Each device shows only the _osc._udp of the other device not it's own.
So behaviour of ESP32 and ESP8266 mDNS query are the same.

@baggior
Copy link
Contributor

baggior commented Feb 17, 2018

@beegee-tokyo initially after the esp32 startup all the service I publish on MDNS are shown by the client (Android Service Browser)
but after some time (about 2 minutes) they disappears and only _workstattion._tcp.local is still visible..

what could be the issue?
is there any refresh needed in general to renew the service announce?

@beegee-tokyo
Copy link
Contributor

beegee-tokyo commented Feb 17, 2018

@baggior I do not make any update to the mDNS services after I fired them up and they still show after hours. But I do not use the _workstation._tcp at the moment. As this is the one you see after the others disappeared, it might be connected to this service. How do you initiate that service? Are you using the enableWorkstation(wifi_interface_t interface) function from the ESPmDNS library or something else?

EDIT
Changed my code and added MDNS.enableWorkstation(ESP_IF_WIFI_STA); and still both services _arduino._tcp and _workstation._tcp are still shown after 10 minutes.

@sorenhl
Copy link

sorenhl commented Jun 1, 2018

@baggior Did you ever find a solution for this?

Tried the example code to align it with the thread:
WiFi.setHostname("ESP32-Test-mDNS"); MDNS.begin("ESP32-Test-mDNS"); MDNS.addService("_osc", "_udp", 4500); MDNS.addServiceTxt("_osc", "_udp", "does", "it"); MDNS.addServiceTxt("_osc", "_udp", "work", "?"); MDNS.addServiceTxt("_osc", "_udp", "yes", "!");

With ESP8266 and this works perfectly, but not with ESP32 (ESP-Wroom-32).
If i use Zeroconf (C#) to discover services my esp8266 shows up with the correct name but ESP32 shows up with name "_osc" and dissapears after like 10 seconds. If I hard-reset it, the same thing happens, it shows up as "_osc" in display name and dissapears again.

Any ideas?

@versamodule
Copy link

FWIW, i was also having the same trouble. I was using Firefox this whole time. I tried it with Opera and using http://esp32.local/ it worked perfect.

@LuckyLuzz
Copy link

LuckyLuzz commented Nov 15, 2018

  MDNS.begin("esp32");
  MDNS.addService("_http", "_tcp", 80);
  MDNS.addServiceTxt("_http", "_tcp", "board", "ESP32");

Works on ESP32 devkit V4 with Opera but not with Firefox or Edge.

@evert-arias
Copy link

Adding the _ in front, worked for me
MDNS.addService("_http", "_tcp", 80);

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
@ggilestro
Copy link

I finally found a workaround for this.
The issue must be linked with the powersave functions because disabling power save on the WIFI solves it for me.

    // We remove power save functions on WiFi to try and solve the mDNS disappearance issue
    WiFi.setSleep(false);

(Here is the full code)

Without that line, the mDNS disappears after 6-12 hours.
With that line, it has been running for 48 hours so far.

austvik added a commit to austvik/arduino that referenced this issue Mar 8, 2024
- Underscore before names per espressif/arduino-esp32#962
- Only one service per port

The combination of both changes is needed to make the service discoverable in OpenHAB

The removal of the published http service is maybe something you don't want,
but as long as it doesn't serve web pages it is maybe OK?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

9 participants