Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By JimDrew
#52061 I have seen examples for changing the hostname like:

WiFi.hostname("MyESPName"); // change name for router detection

Although this compiles correctly, it doesn't work. I can put this in the Setup(), before any WiFi related command or after, and it makes no difference. No matter what I try, the router still sees the name as "ESP_xxxx".

If you know of a way to change this that works, please let me know! I can't be the only one that is having this issue with the Arduino IDE. Thanks!
User avatar
By rudy
#52071 I was really confused with the

WiFi.hostname("MyESPName"); // change name for router detection

Because it didn't work. I'm sure it changes something but not what I needed. I was using the OTA sketch.

What worked for me is the following. Currently I use the last three digits if the IP address to name my modules as I can more easily identify them that way. Much better than the last chars of the MAC address.

Code: Select all#define HOSTNAME "ESP100"          // Set the host name to whatever is appropriate.

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

   

  String hostname(HOSTNAME);             
  wifi_station_set_hostname(strToChar(hostname));  //sdk, non-Arduino function
User avatar
By JimDrew
#52129 I changed the casting so that it compiles without a warning using this:

Code: Select all  String routername = "Testing123";
  char* ourname = &routername[0];
  wifi_station_set_hostname(ourname);  //sdk, non-Arduino function


I put this in the Setup() before the WiFi.begin and it does not change the name that my router sees. I tried moving the code after WiFi.begin and that also did not work. Do you have a simple project that will compile and show this actually working? Thanks!