Skip to content

LwipIntfDev - disconnect()/end() should not clear static IP settings #1866

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

Merged

Conversation

JAndrassy
Copy link
Contributor

when I wrote the test sketch for WiFi libraries I wanted to do begin with DHCP, then begin with static IP and then again begin with DHCP. I thought that disconnect() should clear the static IP for return to DHCP, but it turned out that all libraries I tested preserved the static IP settings over disconnect() (except my WiFiEspAT). I learned that the right way to return to DHCP is config(0) or config(INADDR_NONE). And this really worked in all libraries and in modern Ethernet libraries (the ones with config) too.
So the user of the library can config the static IP and then disconnect and later begin again with the same static IP.

Now WiFiTest and ModernEthernetTest do an additional begin/disconnect to test if the library preserves the static IP over disconnect. And they reported the your library resets the static IP in disconnect()/end().

The fix is easy and with the previous PR with the config with one and two parameters, the config(INADDR_NONE) works to return to DHCP.

The tests are:
WiFiTest
ModernEthernetTest

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay, will be a noop once a new ::begin happens since the IP config is overwritten unconditionally there. Thx!

@earlephilhower earlephilhower merged commit 91183ca into earlephilhower:master Dec 1, 2023
@JAndrassy JAndrassy deleted the intfdev_end_preserve_staticip branch December 1, 2023 19:54
schkovich pushed a commit to schkovich/arduino-pico that referenced this pull request May 24, 2025
earlephilhower added a commit that referenced this pull request May 30, 2025
The IP address is not cleared (even if it is DHCP acquired) between
::begins on the Ethernet classes by design (#1866).  But it is possible
that the WiFi networks being polled by WiFiMulti are different network
configurations, so force a DHCP request explicitly before (re)connecting).

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

Successfully merging this pull request may close these issues.

2 participants