Description
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.