Skip to content
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

Too long DHCP discovery #305

Closed
ntqbit opened this issue Oct 24, 2023 · 2 comments
Closed

Too long DHCP discovery #305

ntqbit opened this issue Oct 24, 2023 · 2 comments

Comments

@ntqbit
Copy link

ntqbit commented Oct 24, 2023

Hello!

I use the latest esp-wifi revision (5578266) att the moment. I run the examples dhcp.rs and embassy_dhcp.rs for ESP32 (ESP32-WROOM-32 DevkitC board).

Most of the times DHCP discovery takes more than 9 seconds, sometimes even up to 30 seconds. Sometimes, however, it takes no time and the MCU immediately gets static IP.
But that happens rarely, about 1 in 10 times. In other times I have to wait ~10 seconds.

Although, the wifi connection and transmission/reception speed is ok (at least for MQTT), no significant delays.
Wifi connection takes almost no time, at most a few seconds.

I used two access points to connect: my home wifi and an access point created by my laptop.
With both of them I observe the same problem. The laptop and therefore the access point are located less than a meter away from the ESP32, so I think the signal quality should be great.

I measured the time it takes for the MCU to send the DHCP discovery packet with wireshark:
image
(192.168.12.1 is the DHCP server, the IP of the laptop's interface, 192.168.12.84 is the leased IP for the

I see that both the discovery and request packets are sent twice. Is that expected behavior?

I need to clarify that the first DHCP discovery packet is usually delayed for ~10 seconds AFTER I see the Wait to get an ip address debug line (source), for both embassy async and blocking versions.

The commands I use to run the examples:

SSID="ssid" PASSWORD="passwd" cargo run --release --example dhcp --features "wifi"
SSID="ssid" PASSWORD="passwd" cargo run --release --example embassy_dhcp --features "wifi async embassy-net embedded-svc"

Do you know what could be the problem?

Thanks!

@bugadani
Copy link
Contributor

embassy-rs/embassy#2104

@ntqbit
Copy link
Author

ntqbit commented Oct 25, 2023

embassy-rs/embassy#2104

Thank you. That helped.
Indeed, following the pull request, resetting the DHCP socket after STA is connected solves the problem and DHCP discovery happens almost immediately.
However, I found that I also need to add a little delay of about 200 ms before resetting the socket. Otherwise, the problem stays.

So the code working for me (blocking version):

....
    println!("{:?}", controller.is_connected());

    let wait_end = current_millis() + 200;
    while current_millis() < wait_end {}
    wifi_stack.reset();

    // wait for getting an ip address
    println!("Wait to get an ip address");
....

@ntqbit ntqbit closed this as completed Oct 25, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants