mDNS example is not working with me
Posted: Sun Feb 14, 2021 9:20 pm
I am starting with esp01s , and I am trying to run the example
the output was
put when i ping it "ping ESP_4E3621.local" or "ping ESP_A0AAD7.local"
it didnt work
how to test them ?
Code: Select all
/*
ESP8266 mDNS-SD responder and query sample
This is an example of announcing and finding services.
Instructions:
- Update WiFi SSID and password as necessary.
- Flash the sketch to two ESP8266 boards
- The last one powered on should now find the other.
*/
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#ifndef STASSID
#define STASSID "My_Home_NetWork"
#define STAPSK "mohamed&aya"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
char hostString[16] = {0};
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("\r\nsetup()");
sprintf(hostString, "ESP_%06X", ESP.getChipId());
Serial.print("Hostname: ");
Serial.println(hostString);
WiFi.hostname(hostString);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (!MDNS.begin(hostString)) {
Serial.println("Error setting up MDNS responder!");
}
Serial.println("mDNS responder started");
MDNS.addService("esp", "tcp", 8080); // Announce esp tcp service on port 8080
Serial.println("Sending mDNS query");
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
Serial.println("mDNS query done");
if (n == 0) {
Serial.println("no services found");
} else {
Serial.print(n);
Serial.println(" service(s) found");
for (int i = 0; i < n; ++i) {
// Print details for each service found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(MDNS.hostname(i));
Serial.print(" (");
Serial.print(MDNS.IP(i));
Serial.print(":");
Serial.print(MDNS.port(i));
Serial.println(")");
}
}
Serial.println();
Serial.println("loop() next");
}
void loop() {
// put your main code here, to run repeatedly:
MDNS.update();
}
the output was
Code: Select all
04:17:46.186 -> setup()
04:17:46.186 -> Hostname: ESP_A0AAD7
04:17:46.512 -> ...............
04:17:50.874 -> Connected to My_Home_NetWork
04:17:50.874 -> IP address: 192.168.1.107
04:17:50.874 -> mDNS responder started
04:17:50.874 -> Sending mDNS query
04:17:51.852 -> mDNS query done
04:17:51.852 -> 1 service(s) found
04:17:51.852 -> 1: ESP_4E3621.local (192.168.1.105:8080)
04:17:51.852 ->
04:17:51.852 -> loop() next
put when i ping it "ping ESP_4E3621.local" or "ping ESP_A0AAD7.local"
it didnt work
how to test them ?