Changing your hostname

By default, the ESP's hostname will be formed by the characters ESP_ followed by the last three address bytes (two hexadecimal digits each) of the MAC address, e.g. ESP_A1B2C3. If you wish to change the hostname to something more meaningful you can change it programmatically in your sketch. The Espressif SDK provides an API to do this.

Step 1

You need to have the header file user_interface.h on your PC. To check whether it exists, you can either search for it or try to compile a sketch that includes it and look for an error message. If you do not have the file, you can download it from Github.

Step 2

In your ESP8266 sketch, add the following code. You need to wrap the #include because the SDK is written in C whereas the ESP8266 code is in C++.

extern "C"
{
#include <user_interface.h>
}

Step 3

Add the following statement to your sketch before the WiFi.begin() statement. The change of hostname is not stored permanently by the ESP8266 and you will need to call the function every time and before you connect to WiFi.

WiFi.hostname("hostname");

See also how to change the MAC address.