mDNS queries and responses on esp8266. Or to describe it another way: An mDNS Client or Bonjour Client library for the esp8266.
This library aims to do the following:
Future goals:
Find information on how to add a library to your Arduino IDE here.
The file mdns.h is well commented. Try looking there for information on specific methods.
To add a simple mDNS listener to an Aruino sketch which will display all mDNS packets over the serial console try the following:
// This sketch will display mDNS (multicast DNS) data seen on the network.
#include <ESP8266WiFi.h>
#include "mdns.h"
// When an mDNS packet gets parsed this optional callback gets called.
void packetCallback(const mdns::MDns* packet){
packet->Display();
packet->DisplayRawPacket();
}
// When an mDNS packet gets parsed this optional callback gets called once per Query.
// See mdns.h for definition of mdns::Query.
void queryCallback(const mdns::Query* query){
query->Display();
}
// When an mDNS packet gets parsed this optional callback gets called once per Query.
// See mdns.h for definition of mdns::Answer.
void answerCallback(const mdns::Answer* answer){
answer->Display();
}
// Initialise MDns.
// If you don't want the optional callbacks, just provide a NULL pointer as the callback.
mdns::MDns my_mdns(packetCallback, queryCallback, answerCallback);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
// setting up Station AP
WiFi.begin("your_wifi_ssid", "your_wifi_password");
// Wait for connect to AP
int tries = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
tries++;
if (tries > 30) {
break;
}
}
Serial.println();
my_mdns.begin();
}
void loop() {
my_mdns.loop();
}
A more complete example which sends an mDNS Question and parses Answers is available in esp8266_mdns/examples/mdns_test/ .
Run Wireshark on a machine connected to your wireless network to confirm what is actually in flight. The following filter will return only mDNS packets: udp.port == 5353
. Any mDNS packets seen by Wireshark should also appear on the ESP8266 Serial console.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4