Skip to content

ESPmDNS not working on Arduino Core 3.3.8 @ ESP32S3 #12556

@sparrowdsg

Description

@sparrowdsg

Board

ESP32S3

Device Description

Custom PCB with geniuine ESP32S3, with external CH340 programmer (connection through header pins). The device runs an async web server together with its own async loop at 300 loops per second. No other performance issues or undefined behaviors.

Hardware Configuration

I2C interface on GPIO 2, 1 is connected with geniuine ADS1115 operating within 3.3V range. Powered with onboard 3.3 VDC power supply with low noise. RGB LED actuated through MOSFETs on GPIO 18, 16, 17. Simple input button on GPIO 15.

Version

v3.3.8

Type

Bug

IDE Name

Arduino IDE 2.3.8

Operating System

Win10, but also every other

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

The ESPmDNS library does not work in STA and AP modes, despite claiming it does. Upon calling MDNS.begin(hostname) it returns TRUE.
CONFIG_MDNS_MAX_INTERFACES is 3. Everything else is copied verbatim from the example included on the official github page. In fact, even the example itself does not work - same behavior when debugging the board through serial, no results seen in mdns-browser or Wireshark. It is also impossible to connect through the .local address.

Wireshark claims the mDNS packets are not being sent at all.

Oddly enough, this library did work on this specific hardware prior to updating my library stack and esp core to 3.3.8. However, same failure mode used to occur in AP mode (and only in AP mode) prior to the update.

Sketch

#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <NetworkClient.h>

const char *ssid = "............";
const char *password = "..............";

// TCP server at port 80 will respond to HTTP requests
NetworkServer server(80);

void setup(void) {
  Serial.begin(115200);

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Set up mDNS responder:
  // - first argument is the domain name, in this example
  //   the fully-qualified domain name is "esp32.local"
  // - second argument is the IP address to advertise
  //   we send our IP address on the WiFi network
  if (!MDNS.begin("esp32")) {
    Serial.println("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");

  // Start TCP (HTTP) server
  server.begin();
  Serial.println("TCP server started");

  // Add service to MDNS-SD
  MDNS.addService("http", "tcp", 80);
}

void loop(void) {
  // Check if a client has connected
  NetworkClient client = server.accept();
  if (!client) {
    return;
  }
  Serial.println("");
  Serial.println("New client");

  // Wait for data from client to become available
  while (client.connected() && !client.available()) {
    delay(1);
  }

  // Read the first line of HTTP request
  String req = client.readStringUntil('\r');

  // First line of HTTP request looks like "GET /path HTTP/1.1"
  // Retrieve the "/path" part by finding the spaces
  int addr_start = req.indexOf(' ');
  int addr_end = req.indexOf(' ', addr_start + 1);
  if (addr_start == -1 || addr_end == -1) {
    Serial.print("Invalid request: ");
    Serial.println(req);
    return;
  }
  req = req.substring(addr_start + 1, addr_end);
  Serial.print("Request: ");
  Serial.println(req);

  String s;
  if (req == "/") {
    IPAddress ip = WiFi.localIP();
    String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at ";
    s += ipStr;
    s += "</html>\r\n\r\n";
    Serial.println("Sending 200");
  } else {
    s = "HTTP/1.1 404 Not Found\r\n\r\n";
    Serial.println("Sending 404");
  }
  client.print(s);

  client.stop();
  Serial.println("Done with client");
}

Debug Message

Below is just the standard debug from serial. Keep in mind - I connected through the IP and obfuscated my WiFi SSID. I also did connect from the browser, but that was using the IP, not the .local address.

............
Connected to XXXX
IP address: 192.168.100.64
mDNS responder started
TCP server started

New client
Request: /
Sending 200
Done with client

Other Steps to Reproduce

I know this used to work back on esp Core 2.x.x but i can't remember which one.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions