mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1403] setHostname does not set the host name #1201
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1201
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
Debug Messages
The host name is ESP32_1BA4AE30.
@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
@tablatronix commented on GitHub (Jun 23, 2022):
Thats the SSID, not the hostname
@DonatelloX commented on GitHub (Jun 23, 2022):
Thank you @tablatronix for reply.
How can I set the SSID name?
@tablatronix commented on GitHub (Jun 23, 2022):
startConfigPortal(SSID)
also why are you starting cp AND using autoconnect?
@olonsoft commented on GitHub (Jun 24, 2022):
@tablatronix
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
MyTestWiFias a connected client. But is showsesp32-8071E0in my case.This only happens on ESP32. The same code on ESP8266 shows at router
MyTestWiFi.@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)
@olonsoft commented on GitHub (Jun 24, 2022):
bool setupHostname(bool restart);is a private function. Unless you mean to modify the source code.@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
@olonsoft commented on GitHub (Jun 24, 2022):
I 've tried what you suggest
setupHostname(true/false). Same result.@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
@olonsoft commented on GitHub (Jun 24, 2022):
No. The code is not missing.
Same code for ESP32 and ESP8266.
ESP32:
ROUTER:
ESP8266:
Router:
@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);andWiFi.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.@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
@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
@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
@tablatronix commented on GitHub (Jun 25, 2022):
https://github.com/tzapu/WiFiManager/issues/1400#issuecomment-1111682560
What version sdk you all on ?
@tablatronix commented on GitHub (Jun 25, 2022):
I pushed a test fix, needing test esp8266 and see if it broke, and older esp32 libs
@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.
@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+APfrom thesetup()as suggested in most of the examples.With that line included, the hostname does not set.
@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.
@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.
@tablatronix commented on GitHub (Jul 29, 2022):
hmm, still not working? I pushed a fix for this, are you using latest git?
@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.
@tablatronix commented on GitHub (Aug 1, 2022):
sorry ill try to cut a new beta
@PeterHouseJr commented on GitHub (Aug 1, 2022):
I will wait for your new beta.
@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.
@tablatronix commented on GitHub (Aug 3, 2022):
Ill try to do it tonight
@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?
@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
@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.
@tablatronix commented on GitHub (Aug 17, 2022):
Is this using either latest git or beta .12?
Are you using a basic example?
@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.
@tablatronix commented on GitHub (Aug 17, 2022):
I will test again with a basic example, and with an s2.
What esp32 version you using?
@PeterHouseJr commented on GitHub (Aug 17, 2022):
ESP32-S2-WROOM from DFRobot DFR0743-WROOM.
Here is some setup info:
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.
@tablatronix commented on GitHub (Aug 17, 2022):
Confirmed, broken here, let me check esp32 again and make sure they didn't change something
@tablatronix commented on GitHub (Aug 18, 2022):
#1068
github.com/tzapu/WiFiManager@b90af1ac4dAdded 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.
@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 . . .
@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:
@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
@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.
@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
@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).
@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
@PeterHouseJr commented on GitHub (Aug 25, 2022):
Have you had any success? Is there anything I can do to help?
@tablatronix commented on GitHub (Aug 26, 2022):
Is it not working?
@PeterHouseJr commented on GitHub (Aug 27, 2022):
Thank you. I missed the commit. I will test this on Monday and let you know.
@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.
@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?
@tablatronix commented on GitHub (Aug 30, 2022):
I have no idea , you should be testing with this library master branch
@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?
@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.
@Erriez commented on GitHub (Sep 12, 2022):
Related to: https://github.com/tzapu/WiFiManager/pull/1483#issuecomment-1243526723
@tablatronix commented on GitHub (Nov 28, 2022):
I think this is fixed now, there may be some wrong behavior in older IDF still, shrug
@Erick20000 commented on GitHub (Dec 20, 2022):
sethostname: usa o miniaplicativo 'Rede' no 'Painel de controle' para definir
o nome do host.
@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?
@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 initializingWiFiManager wm;Of course, this approach may not be desirable in all use cases.
btw: Thank You for providing this library!