ESP32 Setting a Custom Hostname (Arduino IDE)
By default, the hostname of the ESP32 is espressif. In this guide, you'll learn how to set a custom hostname for your board using Arduino IDE programming environment.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelAdvanced
- Available atAjvika Labs, Kakinada
About this project
By default, the hostname of the ESP32 is
espressif
. In this guide, you’ll learn how to set a custom hostname for your board.
To set a custom hostname for your board, call
WiFi.setHostname(YOUR_NEW_HOSTNAME);
before
WiFi.begin();
Setting an ESP32 Hostname
Usually, the default ESP32 hostname is
espressif
or a similar name.
There is a method provided by the
WiFi.h
library that allows you to set a custom hostname.
First, start by defining your new hostname. For example:
const char* hostname = \"esp32-node-temperature\";
Then, call the
WiFi.setHostname()
function before calling
WiFi.begin()
. You also need to call
WiFi.config()
as shown below:
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname.c_str()); //define hostname
You can copy the complete example below (don’t forget to insert your network credentials):
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include `WiFi.h`
// Replace with your network credentials
const char* ssid = \"REPLACE_WITH_YOUR_SSID\";
const char* password = \"REPLACE_WITH_YOUR_PASSWORD\";
// Change the hostname
const char* hostname = \"esp32-node-temperature\";
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname);
WiFi.begin(ssid, password);
Serial.print(\"Connecting to WiFi...\");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.print(\"\
ESP32 IP Address: \");
Serial.println(WiFi.localIP());
Serial.print(\"ESP32 HostName: \");
Serial.println(WiFi.getHostname());
Serial.print(\"RRSI: \");
Serial.println(WiFi.RSSI());
}
void setup() {
Serial.begin(115200);
initWiFi();
}
void loop() {
// put your main code here, to run repeatedly:
}
You can use this previous snippet of code in your projects to set a custom hostname for the ESP32. On the Serial Monitor, you should get the new ESP32 hostname.
Important:
you may need to restart your router for the changes to take effect.
After this, if you go to your router settings, you’ll see the ESP32 with the custom hostname.
Note:
some routers don’t allow you to change the ESP32 hostname using this method. If that’s your case, you’ll need to change it manually on the router’s administration panel.
Wrapping Up
In this tutorial, you’ve learned how to set up a custom hostname for your ESP32. This can be useful to identify the devices connected to your network easily. For example, if you have multiple ESP32 boards connected simultaneously, it will be easier to identify them if they have a custom hostname.
For more Wi-Fi related functions, we recommend the following tutorials:
ESP32 Useful Wi-Fi Library Functions (Arduino IDE)
ESP32 WiFiMulti: Connect to the Strongest Wi-Fi Network (from a list of networks)
[SOLVED] Reconnect ESP32 to Wi-Fi Network After Lost Connection
We hope you’ve found this tutorial useful.
Learn more about the ESP32 with our resources:
Learn ESP32 with Arduino IDE
Build Web Servers with ESP32 and ESP8266
More ESP32 Projects and Tutorials…
espressif
. In this guide, you’ll learn how to set a custom hostname for your board.
To set a custom hostname for your board, call
WiFi.setHostname(YOUR_NEW_HOSTNAME);
before
WiFi.begin();
Setting an ESP32 Hostname
Usually, the default ESP32 hostname is
espressif
or a similar name.
There is a method provided by the
WiFi.h
library that allows you to set a custom hostname.
First, start by defining your new hostname. For example:
const char* hostname = \"esp32-node-temperature\";
Then, call the
WiFi.setHostname()
function before calling
WiFi.begin()
. You also need to call
WiFi.config()
as shown below:
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname.c_str()); //define hostname
You can copy the complete example below (don’t forget to insert your network credentials):
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include `WiFi.h`
// Replace with your network credentials
const char* ssid = \"REPLACE_WITH_YOUR_SSID\";
const char* password = \"REPLACE_WITH_YOUR_PASSWORD\";
// Change the hostname
const char* hostname = \"esp32-node-temperature\";
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname);
WiFi.begin(ssid, password);
Serial.print(\"Connecting to WiFi...\");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.print(\"\
ESP32 IP Address: \");
Serial.println(WiFi.localIP());
Serial.print(\"ESP32 HostName: \");
Serial.println(WiFi.getHostname());
Serial.print(\"RRSI: \");
Serial.println(WiFi.RSSI());
}
void setup() {
Serial.begin(115200);
initWiFi();
}
void loop() {
// put your main code here, to run repeatedly:
}
You can use this previous snippet of code in your projects to set a custom hostname for the ESP32. On the Serial Monitor, you should get the new ESP32 hostname.
Important:
you may need to restart your router for the changes to take effect.
After this, if you go to your router settings, you’ll see the ESP32 with the custom hostname.
Note:
some routers don’t allow you to change the ESP32 hostname using this method. If that’s your case, you’ll need to change it manually on the router’s administration panel.
Wrapping Up
In this tutorial, you’ve learned how to set up a custom hostname for your ESP32. This can be useful to identify the devices connected to your network easily. For example, if you have multiple ESP32 boards connected simultaneously, it will be easier to identify them if they have a custom hostname.
For more Wi-Fi related functions, we recommend the following tutorials:
ESP32 Useful Wi-Fi Library Functions (Arduino IDE)
ESP32 WiFiMulti: Connect to the Strongest Wi-Fi Network (from a list of networks)
[SOLVED] Reconnect ESP32 to Wi-Fi Network After Lost Connection
We hope you’ve found this tutorial useful.
Learn more about the ESP32 with our resources:
Learn ESP32 with Arduino IDE
Build Web Servers with ESP32 and ESP8266
More ESP32 Projects and Tutorials…
Technologies used
Hardware components
- ESP32
- ESP8266
- Arduino
- Raspberry Pi
Software & tools
- Arduino IDE
- Node-RED
- MQTT
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.