-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Hostname not sent via DHCP request #2537
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
Comments
@adydeac we have detected the same issue in project where we use a web server application, I think we detected the problem because we have several ESP32 in the same wifi network , we can't access the esp32's web-server application and we can't ping them on the network until they are connected for some time on the network(3-5minutes) and we believe that is caused because the esp32 exposes all the same host name "espressif" .. Anyone that can guide us on how to properly set the ESP32 host names ? |
This probably should be looked at upstream. https://github.com/espressif/esp-idf/blob/master/components/lwip/port/esp32/netif/wlanif.c#L205. If you add this file into your sketch folder, you could write some code to give each machine a unique name. |
@luisgcu
|
You can set the hostname before calling wifi.begin(). You just need to set the mode first. Then you should get a unique hostname. |
@beegee-tokyo that only sets the mDNS advertised hostname and not the wifi hostname that shows up on the router. But that is good practice to set a unique hostname. |
As you can see from the tcpdump on the router (running openwrt, the gateway, the only DHCP server in the network), there is no hostname sent. Please see tha ascii dump as well. No "espressif" or anything. Something has changed maybe in the latest code? Or we need to enable the hostname sending? |
also with 1.0.2 RC1 ? |
Same. [before update] [after update] The code: Debug messages: |
Move wifi.mode and wifi.sethostname before WiFi.begin. the call to tcpip adapter shouldn't be necessary as that is done inside the wifi library |
WiFi.mode(WIFI_STA); Same: Probably you have noticed that not even the default "espressif" hostname is sent... |
I don't know if toCharArray is mangling it somehow,but I have definitely seen invalid names (non-printable chars) come through while watching a tcpdump on the router. This is working for me:
|
Same result: tcpdump -Anev -s 1024 -i br-lan port 67 or port 68 or port 6910:15:57.942822 30:ae:a4:14:3f:e0 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 0, offset 0, flags [none], proto UDP (17), length 336) I am using the latest dev libraries. Am I doing something wrong? Is my board broken in any way? |
I'm having the same issue (using Wemos LOLIN D32 board). I have also tried every imaginable position of doing the setHostName call:
Whatever I try, the DHCP request sent by the ESP32 never contains a Host Name (DHCP Option 12), unlike for other devices (including ESP8266 boards) which do properly set their hostname. As a result, the router (FritzBox) lists the WiFi device as "espressif" instead of the desired hostname (it's not clear to me where this "espressif" name comes from, because I don't see that anywhere in the DHCP Request either) and the built-in DNS server does not create a record for the hostname. |
Another (less important) issue: I'm creating libraries which work on both ESP8266 and ESP32. The API for setting hostname is currently different between ESP8266 and ESP32:
|
@adydeac this may need to be moved to https://github.com/espressif/esp-idf as the DHCP implementation is implemented there (in the lwip stack actually). |
I'm not very familiar with esp-idf project. Is it another fork? Is it an substitute? Is it part of this project? |
It provides most of the underlying functionality of this project. |
As Ibernstone suggested i was able to make it work like this
It really seems to be related to '\0'.
and it also works |
@maxdd you should not need this two step process to declare a string: char hname[12] = "ESP32-LIGHT";
hname[11] = '\0'; this is all you need: char hname[] = "ESP32-LIGHT"; // the compiler will append a null automagically. Your declaration worked because the compiler did append a null, else it would complain about type mismatch. If you changed the declaration to 13 characters ( Chuck. |
That's curious, last time a tried your "normal/standard" solution it didnt work. |
Still no success for me if I perform the |
WiFi.disconnect is there to make sure the device releases its lease (and clears the info out of nvs). hostname is not given (or requested) on a lease renewal/validation. Both the esp32 and the dhcp server need to see this as a new event. Ultimately, it is up to the dhcp server to report new dns names, so there will be many situations where this will never work. |
Wifi.mode() is required for the disconnect method to do any clearing of NVS IIRC |
I could successfully reproduce that this is a real bug and I created a PR in order to fix it: espressif/esp-lwip#6 The underlying issue has nothing to do with any This bug is a little bit tricky, because it doesn't appear in every operational state. If the in-memory stored previous dhcp lease is e.g. no longer valid there will also be a fresh dhcp request (and hostname propagation). That's maybe the reason why it worked for some of you "sometimes". @luisgcu @rpannekoek You can verify if you are really experiencing the same bug by erasing the complete flash of the esp32 (which in turn clears any previous dhcp lease, leading to a fresh dhcp lease and an updated hostname). This can be done e.g. with esptool or platformio ( |
I can confirm this bug. dnsmasq logging with ESP8266: dnsmasq logging with ESP32: See the missing hostname in the logging of dnsmasq.... Hostname is set for sure btw. |
WORKAROUND: Add I hope issue will be resolved soon. |
The workaround suggested by @jeroenst worked for me! |
After working on this issue for over 4 hours @jeroenst suggestion work for me also. My ESP8266 was not this difficult to do. Thank you very much. WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); |
I just resolved same issue by using @jeroenst suggestion! Sigh! |
I can confirm it too.. With
|
Just a note about ArduinoOTA: The default behaviour of ESP32 ArduinoOTA is to set the hostname to 'esp32-', and this interferes with the workaround. Most examples on the net for ESP32 OTA instructs to use IP-address, so I couldn't find a solution to this problem (maybe I'm ignorant) until i looked at the ArduinoOTA source code. To fix this, manually set the hostname in the OTA-object:
An alternative solution (presumes tha MDNS is already configured):
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
Wake up, Neo. |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
- implemented WA for the ESP32 issue espressif/arduino-esp32#2537 - Delayed reconnection, allows websocket to finish section transaction. Fix #1 Signed-off-by: Emil Muratov <gpm@hotplug.ru>
- implemented WA for the ESP32 issue espressif/arduino-esp32#2537 - Delayed reconnection, allows websocket to finish section transaction. Fix #1 Signed-off-by: Emil Muratov <gpm@hotplug.ru>
commit d7917ef Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 26 18:37:06 2020 +0200 WiFi lost STA fix commit 768bb7a Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 26 17:40:10 2020 +0200 wifi manual reconnect fix commit b75e271 Author: Emil Muratov <gpm@hotplug.ru> Date: Wed Nov 25 20:29:02 2020 +0300 WiFi status fix - fixed updating WiFi station variable (ESP32) - Interface frame size increased for ESP32 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 98d5eb1 Author: Emil Muratov <gpm@hotplug.ru> Date: Wed Nov 25 01:18:37 2020 +0300 Embed system settings vars/GUI - Add system-related vars to the embui initialization code - Predefined code for "settings' web-page - generic example changed to adopt predefined settings UI Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 86dc340 Author: Emil Muratov <gpm@hotplug.ru> Date: Thu Nov 19 16:55:27 2020 +0300 TimeLib: Workaround for newlib bug with <+-nn> timezone names local WA for both esp8266 and esp32 'till fixed in both core's Fix for 8266 already in master esp8266/Arduino#7702 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit a31bd32 Author: Emil Muratov <gpm@hotplug.ru> Date: Thu Nov 19 02:06:53 2020 +0300 WiFi: ESP32 DHCP WA, reconnection fix - implemented WA for the ESP32 issue espressif/arduino-esp32#2537 - Delayed reconnection, allows websocket to finish section transaction. Fix #1 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit b136f84 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Nov 6 18:47:48 2020 +0200 resources commit f276d20 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 18:21:44 2020 +0200 mqtt critical fix commit fee53ef Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 16:19:42 2020 +0200 mqtt fix commit 803c9b6 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 12:58:19 2020 +0200 resources fix commit be4bcb6 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Thu Nov 5 12:15:58 2020 +0200 Upload progress fix commit 7e83cfc Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Wed Nov 4 17:47:12 2020 +0200 resources commit 81b3d5c Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Tue Nov 3 14:33:29 2020 +0200 MQTT log fix commit 1584fd8 Author: Emil Muratov <gpm@hotplug.ru> Date: Tue Nov 3 12:13:44 2020 +0300 OTA: esp8266 fix for gzipped fw image Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit 208e6ec Merge: 3eff570 da552d7 Author: Emil Muratov <gpm@hotplug.ru> Date: Sat Oct 31 15:24:11 2020 +0300 Merge branch 'dev' of github.com:DmytroKorniienko/EmbUI into emdev commit 3eff570 Author: Emil Muratov <gpm@hotplug.ru> Date: Sat Oct 31 15:21:22 2020 +0300 OTA fix for ESP32 Signed-off-by: Emil Muratov <gpm@hotplug.ru> commit da552d7 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 04:32:46 2020 +0200 bugfix mqtt commit cdaf07c Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 00:31:15 2020 +0200 bugfix commit 343649a Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Sat Oct 31 00:21:38 2020 +0200 getAPmac bugfix commit 0521889 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Oct 30 19:54:46 2020 +0200 bugfix commit 92f2907 Author: Dmytro Korniienko <Dmytro.Korniienko@volo.global> Date: Fri Oct 30 19:43:27 2020 +0200 Fix (lost changes)
- implemented WA for the ESP32 issue espressif/arduino-esp32#2537 - Delayed reconnection, allows websocket to finish section transaction. Fix #1 Signed-off-by: Emil Muratov <gpm@hotplug.ru>
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
knock knock |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
Check PR #6659 |
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.1
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Debian
Description:
Hi,
I've noticed that somehow (I guess recently?) the hostname is not sent when making DHCP calls:
tcpdump -Anev -s 1024 -i br-lan port 67 or port 68 or port 69
tcpdump: listening on br-lan, link-type EN10MB (Ethernet), capture size 1024 bytes
01:22:43.011475 30:ae:a4:14:3f:e0 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 0, offset 0, flags [none], proto UDP (17), length 336)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 30:ae:a4:14:3f:e0, length 308, xid 0xaedfb4c4, Flags [none]
Client-Ethernet-Address 30:ae:a4:14:3f:e0
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
MSZ Option 57, length 2: 576
Requested-IP Option 50, length 4: 172.16.0.195
Parameter-Request Option 55, length 12:
Subnet-Mask, Default-Gateway, BR, Domain-Name-Server
Domain-Name, Netbios-Name-Server, Netbios-Node, Netbios-Scope
Router-Discovery, Static-Route, Classless-Static-Route, Vendor-Option
E..P.................D.C.<.}............................0...?...........................................................................................................................................................................................................c.Sc5..9..@2.....7......,./.!y+.........................................
01:22:43.014082 e8:de:27:6d:29:35 > 30:ae:a4:14:3f:e0, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 7494, offset 0, flags [none], proto UDP (17), length 328)
172.16.0.1.67 > 172.16.0.195.68: BOOTP/DHCP, Reply, length 300, xid 0xaedfb4c4, Flags [none]
Your-IP 172.16.0.195
Server-IP 172.16.0.2
Client-Ethernet-Address 30:ae:a4:14:3f:e0
sname "tftp"
file "pxelinux.0"
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 172.16.0.1
Lease-Time Option 51, length 4: 259200
RN Option 58, length 4: 129600
RB Option 59, length 4: 226800
Subnet-Mask Option 1, length 4: 255.255.255.0
BR Option 28, length 4: 172.16.0.255
Default-Gateway Option 3, length 4: 172.16.0.1
Domain-Name-Server Option 6, length 4: 172.16.0.1
Domain-Name Option 15, length 3: "lan"
E..H.F..@..{.........C.D.4Z*............................0...?...........tftp............................................................pxelinux.0......................................................................................................................c.Sc5..6.....3.....:....@;...u...........................lan....
This is the on the same router, but with an request from an android phone:
I am using the ESP-WROOM-32 chipset and Arduino IDE on Linux.
The code snippet is:
Sketch: (leave the backquotes for code formatting)
The text was updated successfully, but these errors were encountered: