-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set host name? #2826
Comments
Yes, if you use the search facility of GitHub to search this repository for |
I found this: wifi_station_set_hostname( "Test" ); But it does not work :/ |
After more digging i found it: WiFi.hostname("Name"); |
It worked for me 👍 |
Can you inform me where is the right Position of
|
You need to call |
Since we're on this topic, what is the correct way to change the hostname
later on? Would the wifi need to be restarted or something?
…On Jul 22, 2017 9:28 AM, "Matthew McMillion" ***@***.***> wrote:
You need to call WiFi.hostname() before WiFi.begin()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2826 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQC6BlUWKPViYWHGw1wCvU9P-cgBb7o2ks5sQfkMgaJpZM4LZ5Iu>
.
|
Doesn t work |
Thank you.
Serial monitor log:
|
And how do you See the Hostname ???
Thanks
Klaus-Dieter 🚴🏊🏼⛵️⛷🎾😊
… Am 12.08.2017 um 19:47 schrieb petely ***@***.***>:
Thank you.
This works:
`
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.hostname("relay");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
`
Serial monitor log:
Connecting to astro-net
..
WiFi connected
Server started
Use this URL to connect: http://192.168.1.54/
from Linux box on the same subnet:
corv-root: ping 192.168.1.54
PING 192.168.1.54 (192.168.1.54) 56(84) bytes of data.
64 bytes from 192.168.1.54: icmp_seq=1 ttl=128 time=6.47 ms
64 bytes from 192.168.1.54: icmp_seq=2 ttl=128 time=1.98 ms
64 bytes from 192.168.1.54: icmp_seq=3 ttl=128 time=1.92 ms
and then ...
corv-root: ping relay
PING relay (192.168.1.54) 56(84) bytes of data.
64 bytes from relay (192.168.1.54): icmp_seq=1 ttl=128 time=2.66 ms
64 bytes from relay (192.168.1.54): icmp_seq=2 ttl=128 time=2.53 ms
64 bytes from relay (192.168.1.54): icmp_seq=3 ttl=128 time=1.89 ms
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
You can see in the router or by nslookup . There seems to be no way of pushing in the hostname to the code, other than settings yourself an array of char and WiFi.hostname(array) By the way, this might help lots of people who needs more detailed WiFi report after connect:
|
WiFi.hostname() is currently working in latest git. Closing as resolved. |
/* in some cases, (I had this problem) need to put after WiFi.begin, this MDNS.begin("hostname"), dontt forget to include this #include <ESP8266mDNS.h>
|
does not seem to be setting the name here. It still uses it's I'm not sure I'm using version 2.4.0 of esp8266/Arduino (yet) but not sure how to find that out. I'd also be happy to upgrade to 2.4.0 if I am not, but not sure how to do that either. |
I'm also seeing the same behaviour @brianjmurrell. I'm using PlatformIO, platform espressif8266 1.6.0, which includes the 2.4.0 release of this project. My code is as follows:
|
Try to restart your router. |
Why? What does my router have to do with setting the hostname on my ESP? |
@lrmoreno007 Well that is embarrassing, but yes it worked. I'm not sure why though, as I am able to change the hostname of virtual machines without having to do that. I guess the DHCP implementation in the Espressif SDK isn't 100% spec compliant. Thanks! |
It's not embarrassing. Depending on the configuration of your network, the router can make the DNS server function, was a possibility and that is why I said that you should try it. And also because it is the best trick of a computer technician ... restart the router xD |
WiFi.hostname is broken in 2.4.0 with lwip-v2. Please update to latest git or use lwip-v1.4. |
Not working for me: void wifiSetup() {
char* WiFi_hostname = "ESP8266-2";
WiFi.config(ip, dns, gateway, subnet_mask);
WiFi.hostname(WiFi_hostname);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to : ");
Serial.println(ssid);
Serial.print("IP address : ");
Serial.println(WiFi.localIP());
Serial.print("GW address : ");
Serial.println(WiFi.gatewayIP());
Serial.print("MAC address : ");
Serial.println(WiFi.macAddress());
if (mdns.begin(WiFi_hostname)) {
Serial.println("mDNS responder started !");
}
} |
You should not set config if you are not using an static IP routing; your router has DHCP activated? If yes, some routers simply block any data from static users. Edit-- you set WIFI_STA; |
It worked for me... void setup(void){ // Wait for connection |
Using hypen ("-") in a hostname seems to cause problems - it shouldn't, but
it did for me...
…On Fri, 30 Mar 2018, 19:57 Tomas Kramaric, ***@***.***> wrote:
Not working for me:
void wifiSetup() {
char* WiFi_hostname = "ESP8266-2";
WiFi.config(ip, dns, gateway, subnet_mask);
WiFi.hostname(WiFi_hostname);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to : ");
Serial.println(ssid);
Serial.print("IP address : ");
Serial.println(WiFi.localIP());
Serial.print("GW address : ");
Serial.println(WiFi.gatewayIP());
Serial.print("MAC address : ");
Serial.println(WiFi.macAddress());
if (mdns.begin(WiFi_hostname)) {
Serial.println("mDNS responder started !");
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2826 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALP8xTKTqzLg8elKXBsQjyZacD27E_Vvks5tjnIWgaJpZM4LZ5Iu>
.
|
It doesn't work right. Sometimes it gets the name I set in WiFi.hostname(), and sometimes it gets the "ESP_xxx" name. |
for me, setHostname helped:
And if you want to fetch the host name later in code: |
If doesn't work, try wash flash, may help |
I tried many of the posted suggestions, but none of them worked for me using 2.5.2 or 2.6_dev.
If you put certain Wifi commands in between the setting of the hostname and WiFi.begin (e.g. WiFi.enableSTA(true)) it no longer works and the hostname becomes again the default "ESP_<id>". It also does not work for soft AP mode.
produces an empty hostname. Adding multiple WiFi.hostname(myhostname) or wifi_station_set_hostname(myhostname) statements before or after WiFi.softAP, does not change the result. Nor does adding MDNS.begin(myhostname); Another question is of course: does it really matter if the hostname is not correctly set? In station mode, clients can use the name provided by the router's DNS (or DHCP) service, while for AP mode, mDNS can be used. |
You might have found a pretty bug, I cannot test what you meant because it's been some 7 months since I stopped with Arduino for now - it might be important to open a new ticked with your code, if those functions in the documentation really don't work. About the hostname, it does not matter if you set it or don't set, other than being able to call the device by name as it is probably automagically linked to a DNS server, otherwise you have to know the dynamic IP - and even so, there are some routers like MikroTik, which do not link the DHCP leases to the DNS cache, making the device hostname useless outside the router management interface. |
Without MCVE we can't help. The one in OP works:
console:
on openwrt router:
Closing edit ah, already closed :) |
It does matter if you are setting up a cluster of sensors and each have their own ID and name. It gets hard to track them by random strings when an actual name is easy to read and display. |
Make the device appear with a meaningful name in router device lists. See discussion: esp8266/Arduino#2826
WiFi.config does not allow setting a custom hostname. At least not in the router control panel list of attached devices. Static IP does not mix well with Custom hostname apparently. |
Try after connected to router, first connect to esp8266 to SSID router after change hostname: while (WiFi.status() == WL_CONNECTED) |
Basic Infos
Is there any command which sets ESP hostname?
I mean name which is displayed on router.
Right now it is something like this:
Router panel screen
I would like to change it.
The text was updated successfully, but these errors were encountered: