[GH-ISSUE #1403] setHostname does not set the host name #1201

Closed
opened 2026-02-28 01:28:59 +03:00 by kerem · 56 comments
Owner

Originally created by @DonatelloX on GitHub (Apr 29, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1403

Basic Infos

Hardware

WiFimanager Branch/Release: Master v2.0.11-beta
ESP32 dev module

Description

setHostname does not set the host name.

Settings in IDE

Arduino IDE 1.8.16
ESP32 Core 1.0.6
WiFimanager Branch/Release: Master v2.0.11-beta

Sketch

#include <WiFiManager.h>

void setup() {
  Serial.begin(115200);
  
   WiFi.mode(WIFI_STA);
   
  WiFiManager wm;
  std::vector<const char *> menu = {"wifi", "exit"};
  wm.setMenu(menu);
  wm.setHostname("MyTestWiFi");
  wm.setWiFiAutoReconnect(true);
  wm.setConfigPortalTimeout(120);
  wm.startConfigPortal();

  if(!wm.autoConnect("MyTestWiFi")) {
    Serial.println("WIFImanager: failed to connect :(");
  } else {
    Serial.println("WIFImanager: connected to " + wm.getWiFiSSID());
  }
}

void loop() {

}

Debug Messages

*wm:[2] Starting Config Portal 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  ESP32_1BA4AE30
*wm:[2] AP has anonymous access! 
*wm:[1] AP IP address: 192.168.4.1
*wm:[2] setting softAP Hostname: MyTestWiFi
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] Portal Timeout In 120 seconds
*wm:[2] Portal Timeout In 97 seconds
*wm:[2] Portal Timeout In 67 seconds
[...]

The host name is ESP32_1BA4AE30.

Originally created by @DonatelloX on GitHub (Apr 29, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1403 ### Basic Infos #### Hardware WiFimanager Branch/Release: Master v2.0.11-beta ESP32 dev module ### Description **setHostname** does not set the host name. ### Settings in IDE Arduino IDE 1.8.16 ESP32 Core 1.0.6 WiFimanager Branch/Release: Master v2.0.11-beta ### Sketch ``` #include <WiFiManager.h> void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFiManager wm; std::vector<const char *> menu = {"wifi", "exit"}; wm.setMenu(menu); wm.setHostname("MyTestWiFi"); wm.setWiFiAutoReconnect(true); wm.setConfigPortalTimeout(120); wm.startConfigPortal(); if(!wm.autoConnect("MyTestWiFi")) { Serial.println("WIFImanager: failed to connect :("); } else { Serial.println("WIFImanager: connected to " + wm.getWiFiSSID()); } } void loop() { } ``` ### Debug Messages ``` *wm:[2] Starting Config Portal *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: ESP32_1BA4AE30 *wm:[2] AP has anonymous access! *wm:[1] AP IP address: 192.168.4.1 *wm:[2] setting softAP Hostname: MyTestWiFi *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] Portal Timeout In 120 seconds *wm:[2] Portal Timeout In 97 seconds *wm:[2] Portal Timeout In 67 seconds [...] ``` The host name is ESP32_1BA4AE30.
kerem 2026-02-28 01:28:59 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@olonsoft commented on GitHub (Jun 23, 2022):

Exactly the same problem here.
The same code on ESP8266 sets the hostname correctly.
But on ESP32 the hostname is "esp32-8071E0"

Same problem and possible solution ? https://github.com/prampec/IotWebConf/pull/254

<!-- gh-comment-id:1164086296 --> @olonsoft commented on GitHub (Jun 23, 2022): Exactly the same problem here. The same code on ESP8266 sets the hostname correctly. But on ESP32 the hostname is "esp32-8071E0" Same problem and possible solution ? [https://github.com/prampec/IotWebConf/pull/254](https://github.com/prampec/IotWebConf/pull/254)
Author
Owner

@tablatronix commented on GitHub (Jun 23, 2022):

Thats the SSID, not the hostname

<!-- gh-comment-id:1164408404 --> @tablatronix commented on GitHub (Jun 23, 2022): Thats the SSID, not the hostname
Author
Owner

@DonatelloX commented on GitHub (Jun 23, 2022):

Thank you @tablatronix for reply.
How can I set the SSID name?

<!-- gh-comment-id:1164436153 --> @DonatelloX commented on GitHub (Jun 23, 2022): Thank you @tablatronix for reply. How can I set the SSID name?
Author
Owner

@tablatronix commented on GitHub (Jun 23, 2022):

startConfigPortal(SSID)

also why are you starting cp AND using autoconnect?

<!-- gh-comment-id:1164445216 --> @tablatronix commented on GitHub (Jun 23, 2022): startConfigPortal(SSID) also why are you starting cp AND using autoconnect?
Author
Owner

@olonsoft commented on GitHub (Jun 24, 2022):

@tablatronix

Thats the SSID, not the hostname

There must be a misunderstanding here. The issue is about the hostname.
As you see in @DonatelloX code, he sets hostname wm.setHostname("MyTestWiFi");.
When the ESP connects to wifi successfully, the router should show MyTestWiFi as a connected client. But is shows esp32-8071E0 in my case.
This only happens on ESP32. The same code on ESP8266 shows at router MyTestWiFi.

<!-- gh-comment-id:1165231536 --> @olonsoft commented on GitHub (Jun 24, 2022): @tablatronix > Thats the SSID, not the hostname There must be a misunderstanding here. The issue is about the **hostname**. As you see in @DonatelloX code, he sets hostname `wm.setHostname("MyTestWiFi");`. When the ESP connects to wifi successfully, the router should show `MyTestWiFi` as a connected client. But is shows `esp32-8071E0` in my case. This only happens on ESP32. The same code on ESP8266 shows at router `MyTestWiFi`.
Author
Owner

@mindforger commented on GitHub (Jun 24, 2022):

the code is a bit confusing, so i might have misread it, but can you try calling setupHostname(restart=False) after setHostname ? it looks like this is missing in the ap start sequence for ESP32

(also with restart=True .. just in case)

<!-- gh-comment-id:1165254051 --> @mindforger commented on GitHub (Jun 24, 2022): the code is a bit confusing, so i might have misread it, but can you try calling setupHostname(restart=False) after setHostname ? it looks like this is missing in the ap start sequence for ESP32 (also with restart=True .. just in case)
Author
Owner

@olonsoft commented on GitHub (Jun 24, 2022):

bool setupHostname(bool restart); is a private function. Unless you mean to modify the source code.

<!-- gh-comment-id:1165269259 --> @olonsoft commented on GitHub (Jun 24, 2022): > ` bool setupHostname(bool restart);` is a private function. Unless you mean to modify the source code.
Author
Owner

@mindforger commented on GitHub (Jun 24, 2022):

yeah, please try that (making it public temporale). I am curious and i don't have a esp32 before weekend to test myself

<!-- gh-comment-id:1165305812 --> @mindforger commented on GitHub (Jun 24, 2022): yeah, please try that (making it public temporale). I am curious and i don't have a esp32 before weekend to test myself
Author
Owner

@olonsoft commented on GitHub (Jun 24, 2022):

yeah, please try that (making it public temporale). I am curious and i don't have a esp32 before weekend to test myself

I 've tried what you suggest setupHostname(true/false). Same result.

<!-- gh-comment-id:1165390085 --> @olonsoft commented on GitHub (Jun 24, 2022): > yeah, please try that (making it public temporale). I am curious and i don't have a esp32 before weekend to test myself I 've tried what you suggest `setupHostname(true/false)`. Same result.
Author
Owner

@mindforger commented on GitHub (Jun 24, 2022):

even the debug output the same? that sounds odd!
from the debug output posted earlier and reading the code i figured that this call might be missing in the esp32 defines

<!-- gh-comment-id:1165445871 --> @mindforger commented on GitHub (Jun 24, 2022): even the debug output the same? that sounds odd! from the debug output posted earlier and reading the code i figured that this call might be missing in the esp32 defines
Author
Owner

@olonsoft commented on GitHub (Jun 24, 2022):

No. The code is not missing.

Same code for ESP32 and ESP8266.

ESP32:

*wm:[1] AutoConnect
*wm:[2] ESP32 event handler enabled
*wm:[2] Setting Hostnames:  My-IoT-App
*wm:[2] Setting WiFi hostname
*wm:[2] Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connecting to SAVED AP: MyTestAP
*wm:[1] connectTimeout not set, ESP waitForConnectResult...
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[2] Connected in 827 ms
*wm:[1] STA IP Address: 192.168.1.231

ROUTER:

MAC-Address	        Host
30:AE:A4:80:71:E0	esp32-8071E0 (192.168.1.231)

ESP8266:

*wm:[1] AutoConnect
*wm:[2] Setting Hostnames:  My-IoT-App
*wm:[2] Setting WiFi hostname 
*wm:[2] Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connecting to SAVED AP: MyTestAP
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[2] Connected in 6422 ms
*wm:[1] STA IP Address: 192.168.1.241

Router:

MAC-Address	        Host
18:FE:34:D5:3F:AF	My-IoT-App (192.168.1.241)
<!-- gh-comment-id:1165492320 --> @olonsoft commented on GitHub (Jun 24, 2022): No. The code is not missing. Same code for ESP32 and ESP8266. ESP32: ``` *wm:[1] AutoConnect *wm:[2] ESP32 event handler enabled *wm:[2] Setting Hostnames: My-IoT-App *wm:[2] Setting WiFi hostname *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to SAVED AP: MyTestAP *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECTED *wm:[1] AutoConnect: SUCCESS *wm:[2] Connected in 827 ms *wm:[1] STA IP Address: 192.168.1.231 ``` ROUTER: ``` MAC-Address Host 30:AE:A4:80:71:E0 esp32-8071E0 (192.168.1.231) ``` ESP8266: ``` *wm:[1] AutoConnect *wm:[2] Setting Hostnames: My-IoT-App *wm:[2] Setting WiFi hostname *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to SAVED AP: MyTestAP *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECTED *wm:[1] AutoConnect: SUCCESS *wm:[2] Connected in 6422 ms *wm:[1] STA IP Address: 192.168.1.241 ``` Router: ``` MAC-Address Host 18:FE:34:D5:3F:AF My-IoT-App (192.168.1.241) ```
Author
Owner

@olonsoft commented on GitHub (Jun 24, 2022):

Looking at the logs, I suspect that the problem might be with the autoconnect feature of ESP32. I see that the connect time of ESP32 is only 827ms. I am thinking that as soon as the ESP32 restarts, it automatically connects to WiFi, BEFORE my code reaches the sethostname(xxx) function.
My code blinks a led for a second on boot before calling wm.autoconnect(ap,psw) and that time might be enough for ESP to connect before any other call to wifi functions.
I'll investigate it further.

Update 1:
I 've tried wm.setCleanConnect(true); and WiFi.disconnect(false,false); WiFi.setAutoConnect(false); at the begining of the setup without success.
I see now that in function setupHostname(bool restart) there is a code to disconnect WiFi if it is already connected. So the problem might be elsewhere.

<!-- gh-comment-id:1165753951 --> @olonsoft commented on GitHub (Jun 24, 2022): Looking at the logs, I suspect that the problem might be with the autoconnect feature of ESP32. I see that the connect time of ESP32 is only 827ms. I am thinking that as soon as the ESP32 restarts, it automatically connects to WiFi, BEFORE my code reaches the `sethostname(xxx)` function. My code blinks a led for a second on boot before calling `wm.autoconnect(ap,psw)` and that time might be enough for ESP to connect before any other call to wifi functions. I'll investigate it further. Update 1: I 've tried `wm.setCleanConnect(true);` and ` WiFi.disconnect(false,false); WiFi.setAutoConnect(false);` at the begining of the setup without success. I see now that in function `setupHostname(bool restart)` there is a code to disconnect WiFi if it is already connected. So the problem might be elsewhere.
Author
Owner

@tablatronix commented on GitHub (Jun 24, 2022):

I swear I test this every other week..
Must be a esp issue, cause I just went through this in another issue, let me check again

<!-- gh-comment-id:1166061683 --> @tablatronix commented on GitHub (Jun 24, 2022): I swear I test this every other week.. Must be a esp issue, cause I just went through this in another issue, let me check again
Author
Owner

@tablatronix commented on GitHub (Jun 24, 2022):

yup definitely an issue, I think there is some issue with when this is called or a race condition.
testing now

<!-- gh-comment-id:1166068513 --> @tablatronix commented on GitHub (Jun 24, 2022): yup definitely an issue, I think there is some issue with when this is called or a race condition. testing now
Author
Owner

@tablatronix commented on GitHub (Jun 24, 2022):

yup ok so there seems to be something going on across versions.
My notes say sethostname MUST be set after sta starts, BUT another issue hinted and I just tested it, that it must be set BEFORE sta starts. SOOOOO

I need to find out if this changed or what

*wm:[1] ESP SDK version: v4.4-beta1-189-ga79dc75f0a

<!-- gh-comment-id:1166080022 --> @tablatronix commented on GitHub (Jun 24, 2022): yup ok so there seems to be something going on across versions. My notes say sethostname MUST be set after sta starts, BUT another issue hinted and I just tested it, that it must be set BEFORE sta starts. SOOOOO I need to find out if this changed or what *wm:[1] ESP SDK version: v4.4-beta1-189-ga79dc75f0a
Author
Owner

@tablatronix commented on GitHub (Jun 25, 2022):

https://github.com/tzapu/WiFiManager/issues/1400#issuecomment-1111682560

What version sdk you all on ?

<!-- gh-comment-id:1166147717 --> @tablatronix commented on GitHub (Jun 25, 2022): https://github.com/tzapu/WiFiManager/issues/1400#issuecomment-1111682560 What version sdk you all on ?
Author
Owner

@tablatronix commented on GitHub (Jun 25, 2022):

I pushed a test fix, needing test esp8266 and see if it broke, and older esp32 libs

  • check hostname works on esp8266
  • check hostname works on older esp32 < 2.0.3
<!-- gh-comment-id:1166160964 --> @tablatronix commented on GitHub (Jun 25, 2022): I pushed a test fix, needing test esp8266 and see if it broke, and older esp32 libs - [ ] check hostname works on esp8266 - [ ] check hostname works on older esp32 < 2.0.3
Author
Owner

@olonsoft commented on GitHub (Jun 25, 2022):

I am on v4.4.1-1-gb8050b365e
I can't test it before Monday. I'll keep you informed.

<!-- gh-comment-id:1166207393 --> @olonsoft commented on GitHub (Jun 25, 2022): I am on v4.4.1-1-gb8050b365e I can't test it before Monday. I'll keep you informed.
Author
Owner

@olonsoft commented on GitHub (Jun 27, 2022):

It works now for both ESP8266 and ESP32.
BUT I had to remove the line WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP from the setup() as suggested in most of the examples.
With that line included, the hostname does not set.

<!-- gh-comment-id:1166957398 --> @olonsoft commented on GitHub (Jun 27, 2022): It works now for both ESP8266 and ESP32. BUT I had to remove the line ` WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP ` from the `setup()` as suggested in most of the examples. With that line included, the hostname does not set.
Author
Owner

@tablatronix commented on GitHub (Jun 27, 2022):

Yeah i am looking into that also , it seems hostname MUST be set before wifi is enabled, used to be connected. I need to find out why this changed in the IDF or if there is just some bug in esp we can fix. If not I can find another wya, I just have ot be careful to not stop and start stuff if it causes even a 500ms delay in connections.

<!-- gh-comment-id:1167506266 --> @tablatronix commented on GitHub (Jun 27, 2022): Yeah i am looking into that also , it seems hostname MUST be set before wifi is enabled, used to be connected. I need to find out why this changed in the IDF or if there is just some bug in esp we can fix. If not I can find another wya, I just have ot be careful to not stop and start stuff if it causes even a 500ms delay in connections.
Author
Owner

@PeterHouseJr commented on GitHub (Jul 29, 2022):

I have the same issue with inability to set the Hostname. The Hostname seems to be the AP Hostname when the configuration was saved.

Removing the WiFi.mode( WIFI_STA ); had no effect.

Otherwise, WiFiManager has been wonderful and saved me a lot of time.

<!-- gh-comment-id:1199785499 --> @PeterHouseJr commented on GitHub (Jul 29, 2022): I have the same issue with inability to set the Hostname. The Hostname seems to be the AP Hostname when the configuration was saved. Removing the WiFi.mode( WIFI_STA ); had no effect. Otherwise, WiFiManager has been wonderful and saved me a lot of time.
Author
Owner

@tablatronix commented on GitHub (Jul 29, 2022):

hmm, still not working? I pushed a fix for this, are you using latest git?

<!-- gh-comment-id:1199912664 --> @tablatronix commented on GitHub (Jul 29, 2022): hmm, still not working? I pushed a fix for this, are you using latest git?
Author
Owner

@PeterHouseJr commented on GitHub (Aug 1, 2022):

I did not know there was a fix and am using 2.0.9. I will update and test and let you know . . .

Thank you.

<!-- gh-comment-id:1201173066 --> @PeterHouseJr commented on GitHub (Aug 1, 2022): I did not know there was a fix and am using 2.0.9. I will update and test and let you know . . . Thank you.
Author
Owner

@tablatronix commented on GitHub (Aug 1, 2022):

sorry ill try to cut a new beta

<!-- gh-comment-id:1201276404 --> @tablatronix commented on GitHub (Aug 1, 2022): sorry ill try to cut a new beta
Author
Owner

@PeterHouseJr commented on GitHub (Aug 1, 2022):

I will wait for your new beta.

<!-- gh-comment-id:1201290908 --> @PeterHouseJr commented on GitHub (Aug 1, 2022): I will wait for your new beta.
Author
Owner

@PeterHouseJr commented on GitHub (Aug 2, 2022):

I tried the 2.0.11beta firmware and still no success setting the Hostname. After calling the setHostname function the getHostname function returns the correct setHostname string but the actual Hostname on the wire is the original AP Hostname.

I tried the following code at the end of Setup() and still no success.
`
Serial.println( "Setup(): set Hostname and Restart" );
WiFi.setHostname( Hostname );
Serial.print( " Set AP Hostname Set to: " );
Serial.println( Hostname );
Serial.print( " Get AP Hostname: " );
Serial.println( WiFi.getHostname() );

Serial.println( " AP soft Restart" );
WiFi.reconnect();
`

I also cleared the lease from the router to make sure the router is not caching the Hostname and also confirmed using ping Hostname from the command line.

<!-- gh-comment-id:1203087622 --> @PeterHouseJr commented on GitHub (Aug 2, 2022): I tried the 2.0.11beta firmware and still no success setting the Hostname. After calling the setHostname function the getHostname function returns the correct setHostname string but the actual Hostname on the wire is the original AP Hostname. I tried the following code at the end of Setup() and still no success. ` Serial.println( "Setup(): set Hostname and Restart" ); WiFi.setHostname( Hostname ); Serial.print( " Set AP Hostname Set to: " ); Serial.println( Hostname ); Serial.print( " Get AP Hostname: " ); Serial.println( WiFi.getHostname() ); Serial.println( " AP soft Restart" ); WiFi.reconnect(); ` I also cleared the lease from the router to make sure the router is not caching the Hostname and also confirmed using ping Hostname from the command line.
Author
Owner

@tablatronix commented on GitHub (Aug 3, 2022):

Ill try to do it tonight

<!-- gh-comment-id:1203405811 --> @tablatronix commented on GitHub (Aug 3, 2022): Ill try to do it tonight
Author
Owner

@PeterHouseJr commented on GitHub (Aug 9, 2022):

Do you have an idea what or where the problem is located? Is it in the WiFiManager library or is the problem deeper in the WiFi library? How can I help?

<!-- gh-comment-id:1208830126 --> @PeterHouseJr commented on GitHub (Aug 9, 2022): Do you have an idea what or where the problem is located? Is it in the WiFiManager library or is the problem deeper in the WiFi library? How can I help?
Author
Owner

@tablatronix commented on GitHub (Aug 9, 2022):

Sorry I got pretty sick this week, I will make a beta tomorrow, the only change was moving the hostname call in autoconnect, you can see the commit above

<!-- gh-comment-id:1208850833 --> @tablatronix commented on GitHub (Aug 9, 2022): Sorry I got pretty sick this week, I will make a beta tomorrow, the only change was moving the hostname call in autoconnect, you can see the commit above
Author
Owner

@PeterHouseJr commented on GitHub (Aug 16, 2022):

I am still having a Hostname issue.

When I start the device from an unconfigured state (AP Mode):

Hostname = 'esp32s2-69A284'
SSID = 'esp32-34B47269A284'
IP = 192.168.4.1

After entering the local WiFi info (STA Mode):

Hostname = 'esp32s2-69A284'
Hostname should be 'ELC-69A284'
IP = 192.168.99.106

Nothing I can do will change the Hostname.

I guess the Hostname, esp32s2-69A284, is from somewhere in the firmware. It is certainly not a string that appears anywhere in my code.

<!-- gh-comment-id:1217105114 --> @PeterHouseJr commented on GitHub (Aug 16, 2022): I am still having a Hostname issue. When I start the device from an unconfigured state (AP Mode): Hostname = 'esp32s2-69A284' SSID = 'esp32-34B47269A284' IP = 192.168.4.1 After entering the local WiFi info (STA Mode): Hostname = 'esp32s2-69A284' Hostname should be 'ELC-69A284' IP = 192.168.99.106 Nothing I can do will change the Hostname. I guess the Hostname, esp32s2-69A284, is from somewhere in the firmware. It is certainly not a string that appears anywhere in my code.
Author
Owner

@tablatronix commented on GitHub (Aug 17, 2022):

Is this using either latest git or beta .12?

Are you using a basic example?

<!-- gh-comment-id:1217301274 --> @tablatronix commented on GitHub (Aug 17, 2022): Is this using either latest git or beta .12? Are you using a basic example?
Author
Owner

@PeterHouseJr commented on GitHub (Aug 17, 2022):

The project is using the latest .12-beta you made available a couple of days ago.

The project was started from an example file from 'Dronbot Workshop'. Everything works great except setHostname.

The development environment is using VSCode and Platformio. Happy to post my source file at your request or if you would like to suggest I use one of the example files from the git page I would be happy to try that out.

Have previously tried many different combinations of intermixing WiFi.h and WiFiManager.h library calls with no success. The Hostname is always the same and I check it using both my DD-WRT router which provides the DHCP and confirm using the command line 'ping Hostname' which has only ever responded to the Hostname esp32s2-69A284.

Thank you for your time and effort creating, maintaining, and troubleshooting this library.

<!-- gh-comment-id:1217346167 --> @PeterHouseJr commented on GitHub (Aug 17, 2022): The project is using the latest .12-beta you made available a couple of days ago. The project was started from an example file from 'Dronbot Workshop'. Everything works great except setHostname. The development environment is using VSCode and Platformio. Happy to post my source file at your request or if you would like to suggest I use one of the example files from the git page I would be happy to try that out. Have previously tried many different combinations of intermixing WiFi.h and WiFiManager.h library calls with no success. The Hostname is always the same and I check it using both my DD-WRT router which provides the DHCP and confirm using the command line 'ping Hostname' which has only ever responded to the Hostname esp32s2-69A284. Thank you for your time and effort creating, maintaining, and troubleshooting this library.
Author
Owner

@tablatronix commented on GitHub (Aug 17, 2022):

I will test again with a basic example, and with an s2.

What esp32 version you using?

<!-- gh-comment-id:1217978877 --> @tablatronix commented on GitHub (Aug 17, 2022): I will test again with a basic example, and with an s2. What esp32 version you using?
Author
Owner

@PeterHouseJr commented on GitHub (Aug 17, 2022):

ESP32-S2-WROOM from DFRobot DFR0743-WROOM.

Here is some setup info:

platform = espressif32
board = esp32-s2-saola-1
framework = arduino
lib_deps = 
	bblanchon/ArduinoJson @ ^6.19.3
	sstaub/Ticker@^4.4.0
	ottowinter/AsyncMqttClient-esphome@^0.8.6

The setup is intended for a Adafruit saola board based on the esp32-s2-wrover module. I am using an esp32-s2-wroom module on my custom pcb since the Adafruit parts were out of stock when I began this project. As far as I can tell, the only difference is the WROVER has extra external serial RAM, PSRAM, which the WROOM does not have.

Please let me know which basic example and I will test also.

<!-- gh-comment-id:1218080933 --> @PeterHouseJr commented on GitHub (Aug 17, 2022): ESP32-S2-WROOM from DFRobot DFR0743-WROOM. Here is some setup info: ``` platform = espressif32 board = esp32-s2-saola-1 framework = arduino lib_deps = bblanchon/ArduinoJson @ ^6.19.3 sstaub/Ticker@^4.4.0 ottowinter/AsyncMqttClient-esphome@^0.8.6 ``` The setup is intended for a Adafruit saola board based on the esp32-s2-wrover module. I am using an esp32-s2-wroom module on my custom pcb since the Adafruit parts were out of stock when I began this project. As far as I can tell, the only difference is the WROVER has extra external serial RAM, PSRAM, which the WROOM does not have. Please let me know which basic example and I will test also.
Author
Owner

@tablatronix commented on GitHub (Aug 17, 2022):

Confirmed, broken here, let me check esp32 again and make sure they didn't change something

<!-- gh-comment-id:1218670090 --> @tablatronix commented on GitHub (Aug 17, 2022): Confirmed, broken here, let me check esp32 again and make sure they didn't change something
Author
Owner

@tablatronix commented on GitHub (Aug 18, 2022):

#1068
github.com/tzapu/WiFiManager@b90af1ac4d

Added a fix, hostname must be set BEFORE any wifi on some versions of IDF, and it seems to differ last time i fixed this.

SO DO NOT setmode() in your code and try this last commit and see if it works

Afaik it is impossible to change hostname, I will work on how to stop and start wifi properly to get this working and to allow changes. Pretty sure wifi has to be turned off then back on, which is going to make connections take forever. So ideally just do NOT do anything wifi in your code before autoconnect.

Another way to fix this, is to call WiFi.setHostname("whatnot") immediately after setup and if it fixes your issue then this bug is responsible.

<!-- gh-comment-id:1218758557 --> @tablatronix commented on GitHub (Aug 18, 2022): #1068 https://github.com/tzapu/WiFiManager/commit/b90af1ac4d1c86e71836041c21b7c6539d60bb72 Added a fix, hostname must be set BEFORE any wifi on some versions of IDF, and it seems to differ last time i fixed this. SO DO NOT setmode() in your code and try this last commit and see if it works Afaik it is impossible to change hostname, I will work on how to stop and start wifi properly to get this working and to allow changes. Pretty sure wifi has to be turned off then back on, which is going to make connections take forever. So ideally just do NOT do anything wifi in your code before autoconnect. Another way to fix this, is to call WiFi.setHostname("whatnot") immediately after setup and if it fixes your issue then this bug is responsible.
Author
Owner

@PeterHouseJr commented on GitHub (Aug 18, 2022):

I have tried the WiFi.setHostname placed as soon as possible after the first call to WiFi to connect the Event messages to an event handler. It is also as soon as possible after the first call to wm which gets the MAC address so I can create the Hostname for the device.

I will try out the new library in a couple of hours . . .

<!-- gh-comment-id:1219612500 --> @PeterHouseJr commented on GitHub (Aug 18, 2022): I have tried the WiFi.setHostname placed as soon as possible after the first call to WiFi to connect the Event messages to an event handler. It is also as soon as possible after the first call to wm which gets the MAC address so I can create the Hostname for the device. I will try out the new library in a couple of hours . . .
Author
Owner

@PeterHouseJr commented on GitHub (Aug 18, 2022):

I made the changes to my 2012-beta files as you suggested.

The reported messages on my debug terminal now seem to show the Hostname has been changed.

The device has changed to a different default Hostname: esp32s2-02003F as shown on the Router and verified by command line ping.

Here is a list of the debug messages. Everywhere in debug messages where I read the Hostname, I now read it back from both the WiFi and wm. The debug messages show this and seem to show the new Hostname has been accepted although both the Router and command line ping show otherwise.

Here are the Debug Messages:

*---*---*---*---*---*---*
* Startup
*---*---*---*---*---*---*
* Version0.5.r3.b84 - 2022-08-18 11:42:30
*---*---*---*---*---*---*
Setup(): Begin
Setup(): Setup Switch NOT Pressed
loadConfigFile() Reading ...
   Mounting File System...
loadConfigFile: mounted file system
   Reading Config
   Opened Config File
   JSON Pretty Result:
{
  "HostnamePrefix": "ELC",
  "MQTTServer": "192.168.99.29"
}
   JSON Parsed Correctly
Setup(): 
   MQTT Server:   192.168.99:29
   Port:1883
   WiFi.getHostname(): esp32s2-02003F
   wm.getWiFiHostname(): esp32s2-02003F
*wm:[2] Added Parameter: HostnamePrefix
*wm:[2] Added Parameter: MQTTServer
Setup(): forceConfig is False
*wm:[1] AutoConnect
WiFiEvent: WiFi Ready
   WiFi.getHostname(): esp32s2-02003F
   wm.getWiFiHostname(): esp32s2-02003F
WiFiEvent: station start
   MAC: 34:B4:72:69:A2:84
   Setting Hostname to: ELC-69A284
   WiFi.getHostname(): esp32s2-02003F
   wm.getWiFiHostname(): esp32s2-02003F
*wm:[2] Setting Hostnames:  ELC-69A284
*wm:[2] Setting WiFi hostname
*wm:[2] ESP32 event handler enabled
*wm:[2] Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connecting to SAVED AP: theCatinthehatstrikesback2
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
WiFiEvent: station connected to AP
WiFiEvent: station got IP from connected AP
   Connected to: theCatinthehatstrikesback2
   RRSI: -53
   WiFi.getHostname(): ELC-69A284
   wm.getWiFiHostname(): ELC-69A284
   IP Address: 192.168.99.105
   MAC Address: 34:B4:72:69:A2:84
MQTT: Connecting ...
MQTT: Connected
MQTT: Session present: 0
MQTT: Publishing stat Boot Message
MQTT: Subscribe acknowledged.
MQTT: packetId: 1
MQTT: qos: 0
MQTT: Subscribe acknowledged.
MQTT: packetId: 2
MQTT: qos: 0
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[2] Connected in 6351 ms
*wm:[1] STA IP Address: 192.168.99.105
Setup(): HostnamePrefix: ELC
Setup(): MQTTServer: 192.168.99.29
Setup(): set Hostname and Reconnect
   Set AP Hostname Set to: ELC-69A284
   WiFi.getHostname(): ELC-69A284
   wm.getWiFiHostname(): ELC-69A284
   WiFi.reconnect()
WiFiEvent: station disconnected from AP
*wm:[2] [EVENT] WIFI_REASON:  8
MQTT: Disconnected
   WiFi.getHostname(): ELC-69A284
   wm.getWiFiHostname(): ELC-69A284
loop() Begin Forever Loop
WiFiEvent: station connected to AP
WiFiEvent: station got IP from connected AP
   Connected to: theCatinthehatstrikesback2
   RRSI: -52
   WiFi.getHostname(): ELC-69A284
   wm.getWiFiHostname(): ELC-69A284
   IP Address: 192.168.99.105
   MAC Address: 34:B4:72:69:A2:84
MQTT: Connecting ...
MQTT: Connected
MQTT: Session present: 0
MQTT: Publishing stat Boot Message
MQTT: Subscribe acknowledged.
MQTT: packetId: 1
MQTT: qos: 0
MQTT: Subscribe acknowledged.
MQTT: packetId: 2
MQTT: qos: 0
<!-- gh-comment-id:1219676769 --> @PeterHouseJr commented on GitHub (Aug 18, 2022): I made the changes to my 2012-beta files as you suggested. The reported messages on my debug terminal now seem to show the Hostname has been changed. The device has changed to a different default Hostname: esp32s2-02003F as shown on the Router and verified by command line ping. Here is a list of the debug messages. Everywhere in debug messages where I read the Hostname, I now read it back from both the WiFi and wm. The debug messages show this and seem to show the new Hostname has been accepted although both the Router and command line ping show otherwise. Here are the Debug Messages: ``` *---*---*---*---*---*---* * Startup *---*---*---*---*---*---* * Version0.5.r3.b84 - 2022-08-18 11:42:30 *---*---*---*---*---*---* Setup(): Begin Setup(): Setup Switch NOT Pressed loadConfigFile() Reading ... Mounting File System... loadConfigFile: mounted file system Reading Config Opened Config File JSON Pretty Result: { "HostnamePrefix": "ELC", "MQTTServer": "192.168.99.29" } JSON Parsed Correctly Setup(): MQTT Server: 192.168.99:29 Port:1883 WiFi.getHostname(): esp32s2-02003F wm.getWiFiHostname(): esp32s2-02003F *wm:[2] Added Parameter: HostnamePrefix *wm:[2] Added Parameter: MQTTServer Setup(): forceConfig is False *wm:[1] AutoConnect WiFiEvent: WiFi Ready WiFi.getHostname(): esp32s2-02003F wm.getWiFiHostname(): esp32s2-02003F WiFiEvent: station start MAC: 34:B4:72:69:A2:84 Setting Hostname to: ELC-69A284 WiFi.getHostname(): esp32s2-02003F wm.getWiFiHostname(): esp32s2-02003F *wm:[2] Setting Hostnames: ELC-69A284 *wm:[2] Setting WiFi hostname *wm:[2] ESP32 event handler enabled *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to SAVED AP: theCatinthehatstrikesback2 *wm:[1] connectTimeout not set, ESP waitForConnectResult... WiFiEvent: station connected to AP WiFiEvent: station got IP from connected AP Connected to: theCatinthehatstrikesback2 RRSI: -53 WiFi.getHostname(): ELC-69A284 wm.getWiFiHostname(): ELC-69A284 IP Address: 192.168.99.105 MAC Address: 34:B4:72:69:A2:84 MQTT: Connecting ... MQTT: Connected MQTT: Session present: 0 MQTT: Publishing stat Boot Message MQTT: Subscribe acknowledged. MQTT: packetId: 1 MQTT: qos: 0 MQTT: Subscribe acknowledged. MQTT: packetId: 2 MQTT: qos: 0 *wm:[2] Connection result: WL_CONNECTED *wm:[1] AutoConnect: SUCCESS *wm:[2] Connected in 6351 ms *wm:[1] STA IP Address: 192.168.99.105 Setup(): HostnamePrefix: ELC Setup(): MQTTServer: 192.168.99.29 Setup(): set Hostname and Reconnect Set AP Hostname Set to: ELC-69A284 WiFi.getHostname(): ELC-69A284 wm.getWiFiHostname(): ELC-69A284 WiFi.reconnect() WiFiEvent: station disconnected from AP *wm:[2] [EVENT] WIFI_REASON: 8 MQTT: Disconnected WiFi.getHostname(): ELC-69A284 wm.getWiFiHostname(): ELC-69A284 loop() Begin Forever Loop WiFiEvent: station connected to AP WiFiEvent: station got IP from connected AP Connected to: theCatinthehatstrikesback2 RRSI: -52 WiFi.getHostname(): ELC-69A284 wm.getWiFiHostname(): ELC-69A284 IP Address: 192.168.99.105 MAC Address: 34:B4:72:69:A2:84 MQTT: Connecting ... MQTT: Connected MQTT: Session present: 0 MQTT: Publishing stat Boot Message MQTT: Subscribe acknowledged. MQTT: packetId: 1 MQTT: qos: 0 MQTT: Subscribe acknowledged. MQTT: packetId: 2 MQTT: qos: 0 ```
Author
Owner

@tablatronix commented on GitHub (Aug 18, 2022):

Yeah unfortunately there is no way to get the actual hostname from the IDF, the esp library just returns what you last tried to set it to ( its just a local variable ) And mayh or may not actually get set in the wifi SDK. afaik it is not exposed in the IDF. So The only real test is to check your network. Maybe we can add a dns ping? shrug

<!-- gh-comment-id:1219685615 --> @tablatronix commented on GitHub (Aug 18, 2022): Yeah unfortunately there is no way to get the actual hostname from the IDF, the esp library just returns what you last tried to set it to ( its just a local variable ) And mayh or may not actually get set in the wifi SDK. afaik it is not exposed in the IDF. So The only real test is to check your network. Maybe we can add a dns ping? shrug
Author
Owner

@PeterHouseJr commented on GitHub (Aug 18, 2022):

I am surprised the reconnect() did not work since it should request the DHCP all over again afaik.

<!-- gh-comment-id:1219732917 --> @PeterHouseJr commented on GitHub (Aug 18, 2022): I am surprised the reconnect() did not work since it should request the DHCP all over again afaik.
Author
Owner

@tablatronix commented on GitHub (Aug 19, 2022):

Ok I am testing some fixes to make sure this always works, good news it does not add too much to connection time to reset

<!-- gh-comment-id:1220151548 --> @tablatronix commented on GitHub (Aug 19, 2022): Ok I am testing some fixes to make sure this always works, good news it does not add too much to connection time to reset
Author
Owner

@PeterHouseJr commented on GitHub (Aug 19, 2022):

I look forward to your edits and will try them in the morning (in Sunny, Rain Soaked NE Florida).

<!-- gh-comment-id:1220152853 --> @PeterHouseJr commented on GitHub (Aug 19, 2022): I look forward to your edits and will try them in the morning (in Sunny, Rain Soaked NE Florida).
Author
Owner

@tablatronix commented on GitHub (Aug 19, 2022):

I need to test older IDF and esp32, I have a feeling they will need custom code to set hostname AFTER wifi_sta is up and not before.

I am thinking pre 4.4. and arduino <2.0

<!-- gh-comment-id:1220195446 --> @tablatronix commented on GitHub (Aug 19, 2022): I need to test older IDF and esp32, I have a feeling they will need custom code to set hostname AFTER wifi_sta is up and not before. I am thinking pre 4.4. and arduino <2.0
Author
Owner

@PeterHouseJr commented on GitHub (Aug 25, 2022):

Have you had any success? Is there anything I can do to help?

<!-- gh-comment-id:1227688819 --> @PeterHouseJr commented on GitHub (Aug 25, 2022): Have you had any success? Is there anything I can do to help?
Author
Owner

@tablatronix commented on GitHub (Aug 26, 2022):

Is it not working?

<!-- gh-comment-id:1229036048 --> @tablatronix commented on GitHub (Aug 26, 2022): Is it not working?
Author
Owner

@PeterHouseJr commented on GitHub (Aug 27, 2022):

Thank you. I missed the commit. I will test this on Monday and let you know.

<!-- gh-comment-id:1229211120 --> @PeterHouseJr commented on GitHub (Aug 27, 2022): Thank you. I missed the commit. I will test this on Monday and let you know.
Author
Owner

@PeterHouseJr commented on GitHub (Aug 29, 2022):

I had an issue while applying the changes to WiFiManager.cpp

The line 3610 showing a change of only comments was found in my WiFiManager at line#3530 and the surrounding code lines matched.

This tells me there are either some lines missing or something does not match.

I am defficient in the use of .git. How can I make sure I have the files with your latest, correct, changes?

I tried the changes as is and as far as I can tell using my pfsense router, Advanced IP Scanner and the command line, there is now a zero length Hostname and the device is only ping-able by IP.

<!-- gh-comment-id:1230642104 --> @PeterHouseJr commented on GitHub (Aug 29, 2022): I had an issue while applying the changes to WiFiManager.cpp The line 3610 showing a change of only comments was found in my WiFiManager at line#3530 and the surrounding code lines matched. This tells me there are either some lines missing or something does not match. I am defficient in the use of .git. How can I make sure I have the files with your latest, correct, changes? I tried the changes as is and as far as I can tell using my pfsense router, Advanced IP Scanner and the command line, there is now a zero length Hostname and the device is only ping-able by IP.
Author
Owner

@PeterHouseJr commented on GitHub (Aug 29, 2022):

Wait - I copied the entire contents of the WiFiManager from github to my editor, line 3612 contains the correct code, and am recompiling.

Same results. 0 lenght Hostname.

I believe the failure is probably now my code which needs refactoring after all the tail chasing I have done to try and make this work.

Please let me know which example I should try and How can I download the entrire WiFiManager library after the last three commits?

<!-- gh-comment-id:1230658333 --> @PeterHouseJr commented on GitHub (Aug 29, 2022): Wait - I copied the entire contents of the WiFiManager from github to my editor, line 3612 contains the correct code, and am recompiling. Same results. 0 lenght Hostname. I believe the failure is probably now my code which needs refactoring after all the tail chasing I have done to try and make this work. Please let me know which example I should try and How can I download the entrire WiFiManager library after the last three commits?
Author
Owner

@tablatronix commented on GitHub (Aug 30, 2022):

I have no idea , you should be testing with this library master branch

<!-- gh-comment-id:1231003081 --> @tablatronix commented on GitHub (Aug 30, 2022): I have no idea , you should be testing with this library master branch
Author
Owner

@PeterHouseJr commented on GitHub (Aug 30, 2022):

When I get the library master branch, it does not have the changes. I know I must be doing something wrong. Can you give me a .git command line to get the correct branch?

<!-- gh-comment-id:1231070817 --> @PeterHouseJr commented on GitHub (Aug 30, 2022): When I get the library master branch, it does not have the changes. I know I must be doing something wrong. Can you give me a .git command line to get the correct branch?
Author
Owner

@PeterHouseJr commented on GitHub (Aug 30, 2022):

@tablatronix Thank you for your help.

The latest commit to master works and it works well.

Thank you again for your time and I hope I have contributed to making the library better without wasting too much of your time.

<!-- gh-comment-id:1231865615 --> @PeterHouseJr commented on GitHub (Aug 30, 2022): @tablatronix Thank you for your help. The latest commit to master works and it works well. Thank you again for your time and I hope I have contributed to making the library better without wasting too much of your time.
Author
Owner

@Erriez commented on GitHub (Sep 12, 2022):

Related to: https://github.com/tzapu/WiFiManager/pull/1483#issuecomment-1243526723

<!-- gh-comment-id:1243546134 --> @Erriez commented on GitHub (Sep 12, 2022): Related to: https://github.com/tzapu/WiFiManager/pull/1483#issuecomment-1243526723
Author
Owner

@tablatronix commented on GitHub (Nov 28, 2022):

I think this is fixed now, there may be some wrong behavior in older IDF still, shrug

<!-- gh-comment-id:1329809503 --> @tablatronix commented on GitHub (Nov 28, 2022): I think this is fixed now, there may be some wrong behavior in older IDF still, shrug
Author
Owner

@Erick20000 commented on GitHub (Dec 20, 2022):

sethostname: usa o miniaplicativo 'Rede' no 'Painel de controle' para definir
o nome do host.

<!-- gh-comment-id:1359495113 --> @Erick20000 commented on GitHub (Dec 20, 2022): sethostname: usa o miniaplicativo 'Rede' no 'Painel de controle' para definir o nome do host.
Author
Owner

@Erick20000 commented on GitHub (Dec 20, 2022):

sethostname: usa o miniaplicativo 'Rede' no 'Painel de controle' para definir
o nome do host.
alguém pode me orientar a fazer isso por favor?

<!-- gh-comment-id:1359496270 --> @Erick20000 commented on GitHub (Dec 20, 2022): sethostname: usa o miniaplicativo 'Rede' no 'Painel de controle' para definir o nome do host. alguém pode me orientar a fazer isso por favor?
Author
Owner

@tinkering4fun commented on GitHub (Dec 21, 2024):

I observed the same symptom on my ESP32 D1 R32 board, and came accross this issue thread while looking for a solution.
rem: I still run Arduino 1.8.19 and esp32 2.0.17 and did not like to update immediately.

Found this workaround for the symptom:
In function setup() add a WiFi.disconnect(); call, just before initializing WiFiManager wm;
Of course, this approach may not be desirable in all use cases.

btw: Thank You for providing this library!

<!-- gh-comment-id:2558261438 --> @tinkering4fun commented on GitHub (Dec 21, 2024): I observed the same symptom on my ESP32 D1 R32 board, and came accross this issue thread while looking for a solution. rem: I still run Arduino 1.8.19 and esp32 2.0.17 and did not like to update immediately. Found this workaround for the symptom: In function setup() add a `WiFi.disconnect();` call, just before initializing `WiFiManager wm;` Of course, this approach may not be desirable in all use cases. btw: Thank You for providing this library!
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#1201
No description provided.