Chat freely about anything...

User avatar
By martinayotte
#45186 Yes, this is well known !
If you set new hostname with wifi_station_set_hostname() before the WiFi.reconnect(), it will provide this hostname to the DHCP server.
User avatar
By PaulRB
#45189 When i try to use wifi_station_set_hostname() i can't get it to compile. It complains about converting the parameter. I have tried giving a quoted string directly, using a *char variable, char[] variable, prefixing the the variable with * or &, everything i can think of... Martin can you give us a working example please?
User avatar
By martinayotte
#45190 Do you include the following ?

Code: Select allextern "C" {
#include "user_interface.h"
}


My sample code is so simple, I doubt your issue is there.

Code: Select allchar HostName[32];
sprintf(HostName, "ESPDuino-%06X", ESP.getChipId());
wifi_station_set_hostname(HostName);
User avatar
By PaulRB
#45209 Solved!

With this cut-down version of the code:
Code: Select all#include <ESP8266WiFi.h>

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

char hostname[] = "Alarm";

WiFiServer server(80);

void setup() {
  wifi_station_set_hostname(hostname);
}

void loop() {
}


I was getting an error, because I was re-defining "hostname", which is already defined somewhere else in another file. I changed this to "myhostname" and now it compiles. I should have read the original error message more carefully, instead of assuming I was passing the parameter by the wrong mechanism.

I can now see the device "Alarm" listed on my router's Wireless Clients page.