Blaine1984
Blaine1984

Reputation: 21

Can I change the mDNS hostname in the loop?

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

Answers (1)

Renan Passos
Renan Passos

Reputation: 31

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

Upvotes: 0

Related Questions