Description
Board
generic
Device Description
Hardware Configuration
No
Version
v2.0.4
IDE Name
VSCode with PlatformIO
Operating System
Windows 11
Flash frequency
PSRAM enabled
no
Upload speed
115200
Description
There are several issues in issue trackers out there in the internet which are stating that the hostname is not set correctly. When diving deeper into the library, it seems that the hostname is only set on one location:
arduino-esp32/libraries/WiFi/src/WiFiGeneric.cpp
Line 1122 in 77065bf
That means set a call of WiFi.setHostname()
does nothing in the first step. It's not even enough to call WiFi.mode(WIFI_MODE_STA);
if the mode was already WIFI_MODE_STA. Because if current mode equals new mode:
arduino-esp32/libraries/WiFi/src/WiFiGeneric.cpp
Line 1109 in 77065bf
no changes are applied.
To set the hostname correctly the following snippet has to be used:
WiFi.mode(WIFI_MODE_APSTA); // or any other mode
WiFi.setHostname("asdf");
WiFi.mode(WIFI_MODE_STA);
If the behavior is known to the user of the class it's simple to use but it's a little bit unintuitive. Does it make sense to at least document this behavior?
Sketch
-
Debug Message
-
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.