Skip to content

DHCP client failed on 2.0.4 #7068

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

Closed
1 task done
tsctrl opened this issue Jul 31, 2022 · 11 comments
Closed
1 task done

DHCP client failed on 2.0.4 #7068

tsctrl opened this issue Jul 31, 2022 · 11 comments
Assignees

Comments

@tsctrl
Copy link

tsctrl commented Jul 31, 2022

Board

ESP32 Dev Module

Device Description

DevKitC

Hardware Configuration

None

Version

v2.0.4

IDE Name

IDF Component, Arduino IDE

Operating System

Windows 10

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

9600

Description

dhcp client failed on 2.0.4
after update to 2.0.4 my dhcp client is not working anymore and i have to do below configuration to call to the internet:

IPAddress STAip(192, 168, 0, 100);
IPAddress STAgateway(192, 168, 0, 1);
IPAddress STAsubnet(255, 255, 255, 0);
IPAddress STAdns(192, 168, 0, 1);

IPAddress primaryDNS(8, 8, 8, 8); // optional
IPAddress secondaryDNS(8, 8, 4, 4); // optional

WiFi.config(STAip, STAgateway, STAsubnet, primaryDNS, secondaryDNS);

else my DNS was not able to automatically assign ip and call to the internet was failed. no error was displayed but i notice that the dns was always set to 255, 255, 255, 255 which i think the cause since it was different that the one in my local network. previously i did not have to do WiFi.config and STA mode automatically configure the connection to my router with proper ip.

Symptom:
Connected to station (Router) but unable to call internet without the static config. seems like the ip assignment was wrong

Thanks

Sketch

#include <WiFi.h>

const char* ssid     = "your_network_name";
const char* password = "your_network_password";
const char* host     = "example.com";
const char* url      = "/index.html";

IPAddress local_IP(192, 168, 31, 115);
IPAddress gateway(192, 168, 31, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

void setup()
{
  Serial.begin(115200);

  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("ESP Mac Address: ");
  Serial.println(WiFi.macAddress());
  Serial.print("Subnet Mask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway IP: ");
  Serial.println(WiFi.gatewayIP());
  Serial.print("DNS: ");
  Serial.println(WiFi.dnsIP());
}

void loop()
{
  delay(5000);

  Serial.print("connecting to ");
  Serial.println(host);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  WiFi.mode(WIFI_AP_STA);
  WiFi.enableSTA(true);

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  Serial.print("Requesting URL: ");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("closing connection");
}

Debug Message

log 1:
I (00:00:55.966) esp_netif_handlers: sta ip: 255.255.255.255, mask: 255.255.255.255, gw: 255.255.255.255
log 2:
[  6610][I] wifiInit(): [WIFI]: WiFi status: 255.
[  6709][I] wifiInit(): [WIFI]: WiFi enabling AP mode...
I (6797) wifi:wifi driver task: 3ffd3bf4, prio:23, stack:6144, core=1
I (6866) wifi:wifi firmware version: 63017e0
I (6910) wifi:wifi certification version: v7.0
I (6960) wifi:config NVS flash: enabled
I (7003) wifi:config nano formating: enabled
I (7051) wifi:Init data frame dynamic rx buffer num: 32
I (7110) wifi:Init management frame dynamic rx buffer num: 32
I (7176) wifi:Init management short buffer num: 16
I (7234) wifi:Init dynamic tx buffer num: 32
I (7278) wifi:Init static rx buffer size: 1600
I (7328) wifi:Init static rx buffer num: 4
I (7427) wifi:Init dynamic rx buffer num: 32
I (12:09:44.307) wifi_init: tcpip mbox: 24
I (12:09:44.357) wifi_init: udp mbox: 6
I (12:09:44.415) wifi_init: tcp mbox: 7
I (12:09:44.466) wifi_init: tcp tx win: 3508
I (12:09:44.533) wifi_init: tcp rx win: 3744
I (12:09:44.584) wifi_init: tcp mss: 836
[  7790][I]wiFiEvent(): : WiFi DEFAULT EVENT: 0.
I (12:09:44.643) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (8045) wifi:mode : sta (0c:dc:7e:0e:d6:f8) + softAP (0c:dc:7e:0e:d6:f9)
I (8106) wifi:enable tsf
I (8108) wifi:Total power save buffer number: 16
I (8162) wifi:Init max length of beacon: 752/752
I (8182) wifi:Init max length of beacon: 752/752
[  8304][I]wifiInit()I (8234) wifi:Set ps type: 1
[  0437]wiFiEvent(): WiFi DEFAULT EVENT: 10.
[  8544]wiFiEvent(): [WIFI]: WiFi DEFAULT EVENT: 11.
I (8797) wifi:Total power save buffer number: 16
[  8881][I]wiFiEvent(): [WIFI]: WiFi DEFAULTV[0T: 10.
[  8887][I] wifiInit(): WIFI_MODE_APSTA - Station IP address: 192.168.4.1 
[  9032][I]wifiInit(): [WIFI]: Connecting to: xxxxxxx.
I (9131) wifi:Set ps type: 0
I (9158) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<1,0>, prof:1
I (9583) wifi:state: init -> auth (b0)
I (9654) wifi:state: auth -> assoc (0)
I (9661) wifi:state: assoc -> run (10)
I (9691) wifi:connected with xxxxx, aid = 1, channel 1, BW20, bssid = xxxx
I (9746) wifi:security: WPA2-PSK, phy: bgn, rssi: -62
I (9809) wifi:pm start, type: 0
[  9869][I] wiFiEvent(): [WIFI]: STA CONNECTED!
I (9842) wifi:AP's beacon interval =s, DTIM period = 1
[ 10322][I] wifiInit0(): [WIFI]: Connected to WiFi!, AP: esp32-XXXX, IP address: 255.255.255.255

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@tsctrl tsctrl added the Status: Awaiting triage Issue is waiting for triage label Jul 31, 2022
@lbernstone
Copy link
Contributor

If you run the included code without the WiFi.config() do you also get 255.255.255.255?

@tsctrl
Copy link
Author

tsctrl commented Jul 31, 2022

without config is getting 255.255.255.255, with config i am getting fixed ip as expected.
i am reverting back @SuGlider changes here and seems to work

3bd9d24

@SuGlider SuGlider self-assigned this Jul 31, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Jul 31, 2022

@tsctrl - Did you try the fix from #7059 and it worked after that or it still doesn't work even with that fix?

I tried the Client Code and it works fine...
It gets the IP Address from DHCP Server (from the AP) when I remove WiFi.config() code).
It also works fine the I use Static IP configuration (keeping WiFi.config() code).

I can't reproduce this issue with Arduino Core 2.0.4

@SuGlider
Copy link
Collaborator

Output with Static IP when accessing "google.com/index.html"

const char* ssid = "WiFiTestSSID";
const char* password = "password";
const char* host = "google.com";
const char* url = "/index.html";

IPAddress local_IP(192, 168, 15, 3);
IPAddress gateway(192, 168, 15, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
[   450][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
[   504][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[   594][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 192.168.15.3, MASK: 255.255.255.0, GW: 192.168.15.1
[   594][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[   601][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
Connecting to WiFiTestSSID
[   653][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: Rogabe1, BSSID: a4:33:d7:cd:c0:28, Channel: 3, Auth: WPA_WPA2_PSK
[   655][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[   656][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.15.3
[   670][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[   677][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.15.3, MASK: 255.255.255.0, GW: 192.168.15.1
.
WiFi connected!
IP address: 192.168.15.3
ESP Mac Address: 78:E3:6D:CD:06:A8
Subnet Mask: 255.255.255.0
Gateway IP: 192.168.15.1
DNS: 8.8.8.8
connecting to google.com
[  6134][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[  6134][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
Requesting URL: /index.html
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/index.html
Content-Type: text/html; charset=UTF-8
Date: Sun, 31 Jul 2022 14:45:42 GMT
Expires: Tue, 30 Aug 2022 14:45:42 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 229
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Connection: close

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/index.html">here</A>.
</BODY></HTML>

closing connection

Output using Dynamic DHCP IP when accessing "google.com/index.html"

void setup()
{
  Serial.begin(115200);

//  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
//    Serial.println("STA Failed to configure");
//  }

  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  // ... 
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
[   450][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
Connecting to WiFiTestSSID
[   504][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[   595][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[   597][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[   597][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
[   657][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: Rogabe1, BSSID: a4:33:d7:cd:c0:28, Channel: 3, Auth: WPA_WPA2_PSK
[   659][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
..[  1659][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.15.16
[  1659][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[  1662][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.15.16, MASK: 255.255.255.0, GW: 192.168.15.1
.
WiFi connected!
IP address: 192.168.15.16
ESP Mac Address: 78:E3:6D:CD:06:A8
Subnet Mask: 255.255.255.0
Gateway IP: 192.168.15.1
DNS: 192.168.15.1
connecting to google.com
[  7135][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[  7135][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
Requesting URL: /index.html
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/index.html
Content-Type: text/html; charset=UTF-8
Date: Sun, 31 Jul 2022 14:49:41 GMT
Expires: Tue, 30 Aug 2022 14:49:41 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 229
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Connection: close

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/index.html">here</A>.
</BODY></HTML>

closing connection

@SuGlider
Copy link
Collaborator

SuGlider commented Jul 31, 2022

@tsctrl -

else my DNS was not able to automatically assign ip

DNS doesn't assign IP Address.
DHCP server usually runs on the WiFi AP router.

The Log Output of this issue doesn't seem to be from Arduino.
Are you using Arduino as Component or something else?

@SuGlider SuGlider added Resolution: Unable to reproduce With given information issue is unable to reproduce and removed Status: Awaiting triage Issue is waiting for triage labels Jul 31, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Jul 31, 2022

@tsctrl - I think that you are using Arduino as Component and your IDF isn't updated
I have submited a change to IDF to deal with the issue of INADDR_NONE from LWIP and Arduino IPAddress Class.
Make sure that your IDF is updated to the latest 4.4.1 4.4.2 version from IDF github.

@h1romas4
Copy link

h1romas4 commented Aug 5, 2022

I had the same issue on ESP32-C3 (M5Stamp). I also use arduino-esp32 as a component.

  • esp-idf v4.4.1 (1329b19f)
  • arduino-esp32 2.0.4 (c93bf11)

An incorrect IP address is returned from DHCP.

esp_netif_handlers: sta ip: 255.255.255.255, mask: 255.255.255.255, gw: 255.255.255.255

I believe I am using esp-idf v4.4.1 correctly.

Incidentally, I upgraded esp-idf to v4.4.2(1b16ef6c) as a trial and the problem was resolved.

@SuGlider
Copy link
Collaborator

SuGlider commented Aug 5, 2022

For Arduino as Component:

It seems that IDF v4.4.2-1-gce1fde4b3b has the update I mentitoned before.
It is also possible to use Arduino Core from the the next branch: https://github.com/espressif/arduino-esp32/tree/idf-release/v4.4

@h1romas4
Copy link

h1romas4 commented Aug 6, 2022

@SuGlider
Thank you for your response!

I can confirm that the combination of esp-idf 4.4.2 and idf-release/v4.4(c25a640) works correctly and the problem is solved.

I (30) boot: ESP-IDF v4.4.2 2nd stage bootloader
I (30) boot: compile time 13:36:24
I (30) boot: chip revision: 3
I (32) boot.esp32c3: SPI Speed      : 80MHz
I (37) boot.esp32c3: SPI Mode       : DIO
I (41) boot.esp32c3: SPI Flash Size : 4MB
...snip...
I (3968) pp: pp rom version: 9387209
I (3968) net80211: net80211 rom version: 9387209
I (3978) wifi:wifi driver task: 3fc9bb24, prio:23, stack:6656, core=0
...snip...
I (4278) wifi:pm start, type: 1
I (4278) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
I (4368) wifi:BcnInt:102400, DTIM:1
I (5468) esp_netif_handlers: sta ip: 192.168.0.10, mask: 255.255.255.0, gw: 192.168.0.1

@asier70
Copy link
Contributor

asier70 commented Aug 8, 2022

I also can confirm that esp-idf ver 4.4.2 solves problem when compiling project with arduino as component.

@SuGlider
Copy link
Collaborator

SuGlider commented Aug 8, 2022

We just merged IDF 4.4.2 into ESP32 Arduino Github - Master branch.
Using latest master will also solve this issue.

Closing this issue at this time.
Feel free to reopen it or open a new one is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants