Reputation: 31
I am using the AT command binary (provided by Espresif) to interface my wi-fi application. In order to identify the device over a network, I've changed the Hostname to a known name, but when I scan the network, the Hostname still being "Espressif", instead of being my "Own Hostname".
Does anyone knows how to fix that? I actually think that it's an error on AT command's binary.
Upvotes: 2
Views: 6181
Reputation: 161
There is a bug in the Espressif code. The workaround is to reset the WIFI before setting hostname and starting the WIFI:
WiFi.disconnect(true);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname);
Also note that the OTA may make the issue even harder to fix. If using MDSN and OTA, please add the following code (after the WIFI-stuff) to ensure that the hostname gets correlcty set:
MDNS.begin(hostname);
ArduinoOTA.setHostname(hostname);
ArduinoOTA.begin();
For details, please read the issue 2537 in the Espressif GitHub repo.
Upvotes: 1
Reputation: 11
After literally more than 10 hours of research, trying to pinpoint, analyze and/or fix the issue one way or another, I gave up and accepted the workaround. You can find it here.
In short, what I do and what works for me is:
WiFi.disconnect();
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); // This is a MUST!
if (!WiFi.setHostname("myFancyESP32")) {
Serial.println("Hostname failed to configure");
}
WiFi.begin(ssid, password);
This is really frustrating but for the time being it seems that the issue comes from the ESP IDF and unless it is fixed there, it will not work.
Upvotes: 1
Reputation: 1
Try to wait for Wifi to set-up. easiest (never the best) way with Delay(150).
Upvotes: 0
Reputation: 466
I've got the same issue.
Code looks like:
#include <Arduino.h>
#include "WiFi.h"
void setup() {
// Start the Wifi connection ...
WiFi.enableSTA(true);
WiFi.begin(ssid, password);
// TODO Hostname setting does not work. Always shows up as "espressif"
if(WiFi.setHostname("myHostname")) {
Serial.printf("\nHostname set!\n");
} else {
Serial.printf("\nHostname NOT set!\n");
}
}
Upvotes: 1