Reputation: 21
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);
}
}
Upvotes: 2
Views: 418
Reputation: 31
It is possible with the method setInstanceName from the mdns lib. I tested on ESP32 and it works.
Upvotes: 0