Open
Description
Board
ESP32 Dev Module
Device Description
ESP32 Dev Module
Hardware Configuration
Base Board with no peripherals.
Version
latest master (checkout manually)
IDE Name
Arduino IDE 2.3.4
Operating System
Windows 11
Flash frequency
80
PSRAM enabled
no
Upload speed
921600
Description
I am working on a battery powered application, hence connection speed to wifi is being tested. I have gone through 1675, but wanted to check if there has been any changes (for good or bad) in this context.
Is the almost 10x time disparity between static ip and dhcp expected?
Sketch
#include <WiFi.h>
const char *ssid = "wifi_ssid";
const char *password = "wifi_password";
void setup() {
Serial.begin(115200);
Serial.print("Start Connect At ");
Serial.println(millis());
uint8_t bssid[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x10, 0x3E };
int32_t channel = 6;
IPAddress local_IP(192, 168, 2, 61);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS); // Static IP connects in ~200mS. Without, Takes upto 2 seconds.
WiFi.begin(ssid, password, channel, bssid, 1);
//WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
}
Serial.println("WiFi connected at ");
Serial.println(millis());
}
void loop() {
esp_sleep_enable_timer_wakeup(10 * 1000000);
esp_deep_sleep_start();
}
Debug Message
Just the time difference in connection, under
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
}
No Error messages.
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
lbernstone commentedon Mar 18, 2025
There's a lot of variables in WiFi connection that are outside of the control of the ESP device. Looking at verbose logs will let you see some of them, but a full understanding of the transaction will require a wireshark. I can see on my esp32 logs that the WiFi negotiation only takes about 100ms. Then, on first connection, DHCP negotiation takes about 3.5sec. On a restart, where the lease can be reused, DHCP only takes 100ms. From this, I can conclude that most of the time is spent by the AP (which is the DHCPd) figuring out a valid address and committing it to memory, not in getting that info back to the esp32.
kapyaar commentedon Mar 18, 2025
Got it, thanks! In my tests, the time difference seemed fairly consistent so I was curious whether any of the scan related parameter was at play.
lbernstone commentedon Mar 19, 2025
scan related parameters? I don't see any scanning in your code. I ran the simplest connection code possible with verbose logging
I get this in the logs:
That gap between STA_CONNECTED and the finish of GOT_IP is the DHCP transaction. Any extra code other than that simple begin is unnecessary (well, some error checking is good). If you aren't allowing the device to save the wifi connection information (which includes the lease info), then that will slow your connection down.
kapyaar commentedon Mar 19, 2025
By scan, I meant channel scan before connecting.
I ran verbose with and without static IP, and I see what you mean.
Connecting to wifi_ssid (with static settings)
Connecting to wifi_ssid (dhcp) with WiFi.persistent(true);
I would have thought that after the first dhcp connect, subsequent connections would be faster with persistent(true), but timing remains the same over repeated sleep/wake/connects.
WiFi.begin(ssid, password, channel, bssid, 1); Seems to be performing about 800ms faster than WiFi.begin(ssid, password);
Connecting with WiFi.begin(ssid, password);
Not sure what those error mean, but it does connect.
lbernstone commentedon Mar 19, 2025
You would need to wireshark (or have logs on the DHCPd) to see exactly what is going on in the dhcp negotiation. But, it seems like the slowdown is not on the esp32.
kapyaar commentedon Mar 19, 2025
I did a quick wireshark capture with WiFi.begin(ssid,pwd) and sleep for 10sec. I see something like this.
And they look like this.
I don't know what I am looking for, so could nt get much mileage out of it. :)
IMO,