2

I need to change the hostname for the mDNS after setup, inside the main loop. Unfortunately, if I call the MDNS.begin inside the loop with a new hostname, it always returns a 0.

Is it possible to change the hostname on the fly, for example by acquiring the hostname from the serial port?

void loop(void) {
  server.handleClient();
  mdns.update();

  while (Serial.available()) {

    h_name = Serial.readString(); // read the incoming data as string

    if (mdns.begin(h_name, WiFi.localIP())) {
      Serial.println("MDNS responder re-started");
      Serial.println("New hostname");
      Serial.println(h_name);
    }

    delay(10);



  }
}
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
Blaine1984
  • 21
  • 1

1 Answers1

0

It is possible with the method setInstanceName from the mdns lib. I tested on ESP32 and it works.