Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By dunk
#42228
PhilHornby wrote:I can't get this one to compile - I'm missing "mdns.h". I tried using the supplied "ESP8266mDNS.h" instead, but that doesn't help.

mdns.h is one of the source files in the library.
specifically: https://github.com/mrdunk/esp8266_mdns/ ... ter/mdns.h

good luck!
dunk.
User avatar
By dunk
#42232
Arunk3001 wrote:I'm trying to use this library to discover and connect to an MQTT server, but I'm having difficulty understanding how to get an IP address out of a request.

i'm presuming "MQTT server" in this case is another computer elsewhere on your network.
this was also what i was trying to do when i wrote this library so it should work for you.

Arunk3001 wrote:The server is responding to server.local when queried from browser, but I can't connect "server.local" to an IP address in the ESP.

what's "browser" in this case?
this library only reports what mDNS traffic is on the network.
you need to configure mDNS on "MQTT server". my MQTT server is Mosquitto running on Linux.
you can see my mDNS configuration file here:
https://github.com/mrdunk/home_automati ... to.service

Arunk3001 wrote:When I run the simple example I can see the server responding to mDNS queries with an IP, but I can't seem to find my way beyond that. Any advice as far as where to look to get started?

when you run the example on the EXP8266 you should see the IP of the "MQTT server" (ie, the other computer your MQTT broker is running on)... so the ESP8266 now knows the IP of the "MQTT server".
isn't that what you want?

it's worth pointing out that the example code does not tell any other device on the network any information about the ESP8266.
it instead requests information about other devices on the network.
User avatar
By tinkerbear
#51319 I'm digging though the code of the ESP8266mDNS "library" (it's a single source file) and it's clearly meant to handle both responding to mDNS requests from other network entities, *and* making queries on the network.

There's a bunch of code there for parsing response packets and storing the data. (I think it has to work this way, because both directions of querying need to use the same port, 5353.)

I just can't get it to work.

After various setup, I make the call (cribbed from example code):
int n = MDNS.queryService("http", "tcp");

Watching packets on the network, it sends a query, and three things on my net reply (two printers and an ip camera -- with completely valid responses). I turned on MDNS_DEBUG_RX in the code and I can see it's receiving the packets - and then throwing them all away after the debug message: "Expected a packet with 4 answers, returning"

If I comment out that entire error check, it gets a bit farther, but still fails.

The parsing code looks really grotty to me. Anyone else fixed it already? Anyone? Bueller?

I suppose I'm going to have to wade into it. :?
User avatar
By dunk
#51427 yea, i ran out of patience trying to get the "official" ESP8266mDNS library to work for queries.
that's why i wrote the library this thread is about. (https://github.com/mrdunk/esp8266_mdns)
if you only need to query mDNS then this library should work for you too. there's a working example included on the github page.