[GH-ISSUE #208] Cannot set hostname or make mDNS work #171

Closed
opened 2026-02-28 01:23:48 +03:00 by kerem · 2 comments
Owner

Originally created by @kdobrev on GitHub (Aug 4, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/208

My esp8266 seems to always have hostname ESP_something as a name.

My setup is:

`void setup()
{
  WiFiManager wifiManager;  // commented here because it is initiallized outside setup()
  wifiManager.setAPCallback(configModeCallback);
  if (!wifiManager.autoConnect("KDO")) {
    Serial.println("failed to connect and hit timeout");
    ESP.reset();
    delay(1000);
    Serial.println("connected...yeey :)");
  }

  WiFi.hostname(host);
  wifi_station_set_hostname("KDO");
  if (!MDNS.begin(host)) {
    Serial.println("Error setting up MDNS responder!");
  }
  server.begin();
  MDNS.addService("http", "tcp", 80);`

Here I use 3 things that according to me should set my hostname, but it is not set and my device is not reachable by hostname on the local network.
in the library itself I cannot find wifi_station_set_hostname
Can I put is somewhere?

Originally created by @kdobrev on GitHub (Aug 4, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/208 My esp8266 seems to always have hostname ESP_something as a name. My setup is: ``` `void setup() { WiFiManager wifiManager; // commented here because it is initiallized outside setup() wifiManager.setAPCallback(configModeCallback); if (!wifiManager.autoConnect("KDO")) { Serial.println("failed to connect and hit timeout"); ESP.reset(); delay(1000); Serial.println("connected...yeey :)"); } WiFi.hostname(host); wifi_station_set_hostname("KDO"); if (!MDNS.begin(host)) { Serial.println("Error setting up MDNS responder!"); } server.begin(); MDNS.addService("http", "tcp", 80);` ``` Here I use 3 things that according to me should set my hostname, but it is not set and my device is not reachable by hostname on the local network. in the library itself I cannot find wifi_station_set_hostname Can I put is somewhere?
kerem closed this issue 2026-02-28 01:23:48 +03:00
Author
Owner

@gordonthree commented on GitHub (Aug 13, 2016):

Hostname registration seems hit and miss. A lot of consumer wifi routers use DNSMASQ for dhcp and local dns caching, and it seems picky about registering certain hostnames and ignoring others. I haven't had a chance to dig into the dnsmasq docs, to understand how hostname registration works.

I have the same code running on ten different ESP, exactly the same model. Some of them register as their hostname, some register as ESP_xxxxx and some don't register any hostname at all (show up as * in dnsmasq). I can't figure out why this happens, since it's identical code running on identical model ESP.

The variable "host" in your example, is it char, const char or String?

I've tried invoking WiFI.hostname() before and after WiFiManager, it didn't seem to make a difference.

I guess this puts me in the "me too" category.

<!-- gh-comment-id:239643689 --> @gordonthree commented on GitHub (Aug 13, 2016): Hostname registration seems hit and miss. A lot of consumer wifi routers use DNSMASQ for dhcp and local dns caching, and it seems picky about registering certain hostnames and ignoring others. I haven't had a chance to dig into the dnsmasq docs, to understand how hostname registration works. I have the same code running on ten different ESP, exactly the same model. Some of them register as their hostname, some register as ESP_xxxxx and some don't register any hostname at all (show up as \* in dnsmasq). I can't figure out why this happens, since it's identical code running on identical model ESP. The variable "host" in your example, is it char, const char or String? I've tried invoking WiFI.hostname() before and after WiFiManager, it didn't seem to make a difference. I guess this puts me in the "me too" category.
Author
Owner

@kdobrev commented on GitHub (Aug 18, 2016):

At work I think there is no chance to get a hostname in my corporate network, but at home I get these ESP_xxxxx. What I found out in a threat here was that we need to place wifi_station_set_hostname("KDO"); before any network operation has occurred so my code currenlty is:

const char* host = "CloudLamp";
//other stuff
void setup()
{
  Serial.begin(115200);
  //pin stuff
  //display stuff
  wifi_station_set_hostname("CloudLamp");
  WiFiManager wifiManager;  // commented here because it is initiallized outside setup()
  wifiManager.setAPCallback(configModeCallback);
 if (!wifiManager.autoConnect("CloudLamp")) {
    Serial.println("failed to connect and hit timeout");
    ESP.reset();
    delay(1000);
    Serial.println("connected...yeey :)");
  }
  WiFi.hostname(host);
  if (!MDNS.begin(host)) {
    Serial.println("Error setting up MDNS responder!");
  }
  server.begin();
  MDNS.addService("http", "tcp", 80);
 //and so on

I still haven't tested this at home to check if it works.

@gordonthree You say it is up to the router to get a hostname from the ESP and some routers get it and some don't? Or these ESPs you talk about are in one and the same network?

Or you say it is up to every individual ESP chip?

<!-- gh-comment-id:240745263 --> @kdobrev commented on GitHub (Aug 18, 2016): At work I think there is no chance to get a hostname in my corporate network, but at home I get these ESP_xxxxx. What I found out in a threat here was that we need to place wifi_station_set_hostname("KDO"); before any network operation has occurred so my code currenlty is: ``` const char* host = "CloudLamp"; //other stuff void setup() { Serial.begin(115200); //pin stuff //display stuff wifi_station_set_hostname("CloudLamp"); WiFiManager wifiManager; // commented here because it is initiallized outside setup() wifiManager.setAPCallback(configModeCallback); if (!wifiManager.autoConnect("CloudLamp")) { Serial.println("failed to connect and hit timeout"); ESP.reset(); delay(1000); Serial.println("connected...yeey :)"); } WiFi.hostname(host); if (!MDNS.begin(host)) { Serial.println("Error setting up MDNS responder!"); } server.begin(); MDNS.addService("http", "tcp", 80); //and so on ``` I still haven't tested this at home to check if it works. @gordonthree You say it is up to the router to get a hostname from the ESP and some routers get it and some don't? Or these ESPs you talk about are in one and the same network? Or you say it is up to every individual ESP chip?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#171
No description provided.