EspMQTTClient
EspMQTTClient copied to clipboard
Fixed hostname on ESP32
This commit fixes the hostname not getting applied on ESP32 since WiFi.mode()
was called before setting the hostname.
Explanation
Taking a look at the WiFi library,
you can see setHostname method calls set_esp_netif_hostname which sets the default_hostname
variable with the provided hostname.
This variable is read only by get_esp_netif_hostname which gets called in mode and only when the mode is changed to WIFI_MODE_STA
ref
TL;DR
- Call
WiFi.setHostname()
to set internal variabledefault_hostname
with desired hostname. - Call
WiFi.mode()
with parameterWIFI_STA
which will apply the hostname.
Tested and working on ESP32 (Arduino-ESP32 v2.0.17) and no breaking changes found on ESP8266.