kolban wrote:
I tested the function and, just as you said, when I look at my WiFi access point's definitions of attached devices, I still see "espressif" after having made a call to tcpip_adapter_set_hostname(). The one possible wild guess I have is that the access point "remembers" the first name for a given MAC address that it finds.
I think kolban's guess is correct.
The ESP32 appends its hostname to DHCP request, discover, renew and bind requests. So initially it will have been appended 'espressif' and later it would be the new value. You could use a packet capture to confirm this.
Something to also verify is that you set the hostname before WiFi connects and these DHCP requests go out.
However, even if the correct name is sent on the newer DHCP packets, when the router grants the DHCP lease it probably saves the hostname is saw in the original request. It may not bother updating this if the hostname for the MAC changed later. You may have to wait for the DHCP lease to expire (or change the MAC of the ESP32 with esp_wifi_set_mac(), so it looks like a brand new device to the router.)
For further details on the intricacies of DHCP, the Wikipedia page is pretty good:
https://en.wikipedia.org/wiki/Dynamic_H ... n_Protocol - and it links to the RFCs with even more detail if needed.
In IDF, the dhcp client implementation can be found in components/lwip/core/ipv4/dhcp.c (function dhcp_option_hostname adds the hostname to the DHCP request packet.)