Comments on: ESP32 Setting a Custom Hostname (Arduino IDE) https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Tue, 11 Jun 2024 09:08:51 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Scootz https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-876307 Wed, 06 Dec 2023 12:17:24 +0000 https://randomnerdtutorials.com/?p=103157#comment-876307 I tried Heinz’s adaptation and this also had no effect — DHCP request still hardcodes “ESP-C54490”.

I’m using Arduino IDE 1.8.19 with the ESP board support 2.0 (I also tried 3.0-alpha)

Could someone post a complete sourcecode listing that works?
Ideally I am also trying to set MAC address (MAC change works, and would negate need to restart the router). For troubleshooting purposes I just run what’s in this blog post.. and another try using code modified per Heinz’s comment.

I could fill a page of text with all the links I found in Google about how this was broken in Espressif libraries, and then “fixed”, with people saying the problem has come back, but the Espressif Git issues are locked closed..

Without DHCP control, I will have to substitute Raspberry Pis instead.

]]>
By: Heinz Ruetschi https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-821369 Fri, 24 Feb 2023 20:28:20 +0000 https://randomnerdtutorials.com/?p=103157#comment-821369 With an ESP32-S the above mentioned solution did not work.
However when changing the order of of code to this:
const char* newHostname = “ESP32-Test”;
WiFi.setHostname(newHostname); //define hostname
WiFi.mode(WIFI_STA); // station mode
WiFi.begin(ssid, password);

the newHostname was accepted and reacable via ping ESP32-Test

]]>
By: John Sheedy https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-806508 Thu, 29 Dec 2022 22:26:23 +0000 https://randomnerdtutorials.com/?p=103157#comment-806508 In reply to C Munque.

Use mDNS to set a local address.

]]>
By: Allen Mulvey https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-769176 Fri, 15 Jul 2022 14:07:48 +0000 https://randomnerdtutorials.com/?p=103157#comment-769176 In reply to C Munque.

Not having a local DNS server complicates things but the device is apparently getting an IP from a DHCP server, probably in your router. Look and see what HostName is shown in the DHCP address leases for that IP. That should work.

]]>
By: Allen Mulvey https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-769175 Fri, 15 Jul 2022 13:55:10 +0000 https://randomnerdtutorials.com/?p=103157#comment-769175 I use the following code to get a unique Host Name in the familiar form of “ESP_” plus the last 6 hex digits of the MAC address.

Global Variable:
char Host_Name[11];

Local:
byte mac[6];
WiFi.macAddress(mac);
sprintf(Host_Name, “ESP_%02X%02X%02X”, mac[3], mac[4], mac[5]);
WiFi.setHostname(Host_Name);

]]>
By: Pete https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-741757 Wed, 27 Apr 2022 13:31:16 +0000 https://randomnerdtutorials.com/?p=103157#comment-741757 at least in the latest libs (2.0.3), WiFi.setHostname() needs to be called before WiFi.mode(), it is not sufficient to call it before just before WiFi.begin().

]]>
By: C Munque https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-668877 Mon, 13 Sep 2021 15:31:37 +0000 https://randomnerdtutorials.com/?p=103157#comment-668877 Update: For a brief moment I got positive results from using
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(“CustomHostname”);
But not in the way described.

After giving up on WiFi.setHostname() entirely, connecting without it to a static IP, a day later I noticed the ESP was accessible by both the static LAN IP and the customized hostname I’d given it.

Haven’t been able to repeat it since, but it suggests ESP32 remembers a prior WiFi.setHostname attempt such that a subsequent WiFi.config with definitive values (as opposed to INADDR_NONE) gives you the ability to completely control your IP addresses and your hostname, both.

]]>
By: Tommy Ekholm https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-668824 Mon, 13 Sep 2021 07:58:13 +0000 https://randomnerdtutorials.com/?p=103157#comment-668824 In reply to C Munque.

Look at mDNS if you want to use http://esp32test.local

]]>
By: C Munque https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-668526 Sat, 11 Sep 2021 13:35:25 +0000 https://randomnerdtutorials.com/?p=103157#comment-668526 I was hoping to access the esp32 via browser using the hostname

In this case I set my hostname to “esp32test”.

I’m able to see that the device connects to the router, and the router shows the LAN IP as well as the hostname above.

I was hoping to access the server via browser at http://esp32test or http://esp32test.local or possibly http://esp32test.home.

None of these work. http://<Esp32'sLanIp&gt; works fine.

Is possible access the device using hostname?

]]>
By: Carl Hage https://randomnerdtutorials.com/esp32-set-custom-hostname-arduino/#comment-597084 Tue, 27 Apr 2021 23:48:37 +0000 https://randomnerdtutorials.com/?p=103157#comment-597084 Good idea to set a nice host name. But spaces are not a normally valid character and smaller names are better, so “esp32temp” or “officetemp” are better names. Also, skip the overly complex c++ and just use plain C like in the SSID:
const char* hostname = “esp32temp”;
WiFi.setHostname(hostname);

The valid letters for hostname are a-z 0-9 and -.

]]>