Skip to content

Conversation

@1Prototype1
Copy link

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

  1. Call WiFi.setHostname() to set internal variable default_hostname with desired hostname.
  2. Call WiFi.mode() with parameter WIFI_STA which will apply the hostname.

Tested and working on ESP32 (Arduino-ESP32 v2.0.17) and no breaking changes found on ESP8266.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant