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

WiFiSTA - allow using DHCP again after disconnecting static IP #9020

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

JAndrassy
Copy link
Contributor

reset _useStaticIp to false in WiFi.disconnect()

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

LGTM

@d-a-v d-a-v merged commit 0c599ee into esp8266:master Nov 10, 2023
28 checks passed
@JAndrassy JAndrassy deleted the wifi_dhcp_restart branch November 10, 2023 10:59
@mcspr
Copy link
Collaborator

mcspr commented Nov 11, 2023

https://github.com/esp8266/Arduino/blob/1c624dd/doc/esp8266wifi/station-class.rst#config

If you pass all three parameter as 0.0.0.0 (local_ip, gateway and subnet), it will re enable DHCP

In our docs this is mentioned right at the end. Might be more discover-able if moved to the top? Plus, what updated disconnect() behaviour from this PR.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented Nov 11, 2023

@mcspr
I know about config(0,0,0,0). it looks like a workaround.
Do you think resetting back to DHCP in disconnectis not right? That some sketch may want after invoking disconnect() join the network with same previously configured static IP?

I try to find the common Arduino WiFi API so there are as few differences as possible between various WiFi libraries. But config(0, 0, 0, 0) would be hard 'hard to sell'. Having disconnect() reset to DHCP is much simpler.

@mcspr
Copy link
Collaborator

mcspr commented Nov 11, 2023

I only thought about docs... But, considering some examples, that definitely breaks something like this? Where user would expect config() to persist and does not to always pair config() and begin(). Not sure how other cores and libs behave here

setup() {
  WiFi.config()
}
loop() {
  WiFi.begin(foo, bar)
  ... work ...
  WiFi.disconnect()
}

For config, might be another method?

config() {
  config(0, 0, 0, 0)
}

@JAndrassy
Copy link
Contributor Author

I am too tired now, but I will revert this tomorrow. In esp32 too. config(0) gives more control to the user of the library. I will try to steer other libraries to config(0), if they don't support it already.

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.

None yet

3 participants