Wifi: Changing Hostname

tim-hilt
Posts: 5
Joined: Thu Feb 29, 2024 4:03 pm

Wifi: Changing Hostname

Postby tim-hilt » Thu Mar 21, 2024 9:57 pm

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?

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi: Changing Hostname

Postby chegewara » Fri Mar 22, 2024 12:53 am

Did you try to start wifi before _set_hostname?

tim-hilt
Posts: 5
Joined: Thu Feb 29, 2024 4:03 pm

Re: Wifi: Changing Hostname

Postby tim-hilt » Fri Mar 22, 2024 7:31 am

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?

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi: Changing Hostname

Postby chegewara » Mon Mar 25, 2024 7:13 pm

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

Who is online

Users browsing this forum: joglz8, tomy983 and 176 guests