WiFi Hostname is only set when changing mode to WIFI_MODE_STA #7227
Labels
Area: BT&Wifi
BT & Wifi related issues
Type: Documentation
Issue pertains to Documentation of Arduino ESP32
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 callWiFi.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:
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
The text was updated successfully, but these errors were encountered: