ESP8266 icon indicating copy to clipboard operation
ESP8266 copied to clipboard

Fix mDNS examples

Open subraizada3 opened this issue 4 years ago • 2 comments

The current mDNS example, which uses only MDNS.begin(), did not work at all for me.

I looked at the ESP8266 mDNS examples (https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS) and they all have MDNS.update() in the loop - added in the latest commit in December 2018, so presumably this is a new change to the API.

Adding the update call fixed mDNS for me. For this PR I searched for all the files which contain MDNS.begin() and added MDNS.update() to them. The need for the update call in the main loop should probably also be mentioned in the chapter 8 text, but I'm not sure how exactly to add that to the PR so I'll leave that up to you :)

As a note, when my main loop was 2.05 seconds long I got mDNS resolution timeouts on my computer, even though I was calling MDNS.update() once per loop and delay() many times per loop (and delay() is supposed to let background tasks run - apparently MDNS is not one of those). Splitting the main loop to alternate between two 1-seconds segments fixed the issue. So MDNS.update() shouldn't be left uncalled for more than a second or so. But this is probably specific to the timeout value of the mDNS resolver; for me that was Avahi.

subraizada3 avatar Mar 27 '20 04:03 subraizada3

Thanks for the PR!

There have been some significant changes to the ESP8266 Core API since I published this guide, and sadly, I'm no longer up to date with all these changes, because I haven't used the ESP8266 for the last two years or so.

I started working on an updated version last year, but I didn't have the time to update all outdated information and do research on how to use the newer versions of the ESP8266 Core.

I hope to find the time soon to update it, so I can change the code in the guide itself as well.

tttapa avatar Mar 28 '20 17:03 tttapa

I got hung up on the missing MDNS.update() command needed to make this work. This pull request should be merged as it fixes the problem in the code examples. I can understand how the guide is less straight-forward to update but I imagine a number of people have run into the same dead end on getting mDNS to work on the 8266.

Wonderful work on the guide BTW, thank you for it!

szczys avatar Sep 20 '20 22:09 szczys