-->
Page 1 of 5

How do you REALLY change the host name?

PostPosted: Wed Aug 03, 2016 8:13 pm
by JimDrew
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!

Re: How do you REALLY change the host name?

PostPosted: Wed Aug 03, 2016 11:25 pm
by rudy
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

Re: How do you REALLY change the host name?

PostPosted: Thu Aug 04, 2016 11:13 am
by JimDrew
The function strToChar does not compile under Arduino. Is there some other include that is missing?

Re: How do you REALLY change the host name?

PostPosted: Thu Aug 04, 2016 1:02 pm
by JimDrew
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!