Page 1 of 1

Wifi: Changing Hostname

Posted: Thu Mar 21, 2024 9:57 pm
by tim-hilt
I tried adapting the wifi-station-example (https://github.com/espressif/esp-idf/bl ... ple_main.c), so that the hostname is changed via

Code: Select all

esp_netif_set_hostname
.

More specifically, I changed this line from the example:

Code: Select all

esp_netif_create_default_wifi_sta();
to this:

Code: Select all

esp_netif_t* netif = esp_netif_create_default_wifi_sta();
  ESP_ERROR_CHECK(esp_netif_set_hostname(
      netif, "something"));
The code compiles and runs just fine, however the hostname is still showns as "espressif" when looking at my home-network.

How do I have to change the wifi-station-example, so that the hostname is adapted?

Re: Wifi: Changing Hostname

Posted: Fri Mar 22, 2024 12:53 am
by chegewara
Did you try to start wifi before _set_hostname?

Re: Wifi: Changing Hostname

Posted: Fri Mar 22, 2024 7:31 am
by tim-hilt
chegewara wrote:
Fri Mar 22, 2024 12:53 am
Did you try to start wifi before _set_hostname?
Thanks for your reply! I moved the _set_hostname call after

Code: Select all

ESP_ERROR_CHECK(esp_wifi_start() );
, but unfortunately the hostname still isn't changed.

Do I have to change the hostname after wifi is connected maybe? Or as soon as there is an IP address assigned?

Re: Wifi: Changing Hostname

Posted: Mon Mar 25, 2024 7:13 pm
by chegewara
To be honest i dont know what is the correct order, because i am using half-automated library for this, but i have some weird observation.
It is working on some routers and on the other routers it shows old "espressif" hostname.
Im guessing that the 2nd case, when it shows "espressif" hostname is not updating it and remember first hostname associated with esp32 MAC.

Works on huawei HG8245Q2, is not working on TP-link deco M4, with exactly the same code.


PS after short time even tp-link deco is updating esp32 according to hostname set in the code