Wifi.setHostname problem with ESP32dev Board version 2.00 and higher #7446
JaroslavLinhart
started this conversation in
General
Replies: 1 comment
-
Move sethostname before WiFi.mode(WIFI_STA); Hostname is only applied when starting WiFi. This is a limitation of the current Arduino and possibly IDF architecture. It has confused lots of people. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have problem with Wifi.setHostname problem with ESP32dev Board version 2.00 and above. It works for version up to 1.06 and does not work from version 2.00 and higher. Instead of the text that I want to write in hostName, ESP32-303754 or another number depending on the chip will be written.
Wifi.getHostname prints the required text and only ESP32-303754 is visible on the mikrotik DHCP router.
Don't know how to solve this?
#include <WiFi.h>
// Replace with your network credentials (STATION)
const char* ssid = "xxxxx";
const char* password = "xxxxx";
String hostname = "ESP32HumidityNode";
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname.c_str()); //define hostname
//wifi_station_set_hostname( hostname.c_str() );
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
initWiFi();
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());
Serial.print("Host name: ");
Serial.println(WiFi.getHostname());
delay(1000);
}
void loop() {
}
Beta Was this translation helpful? Give feedback.
All reactions