Skip to content

ports/esp8266: Add auto_connect & reconnects options to WLAN.config(). #9460

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

glenn20
Copy link
Contributor

@glenn20 glenn20 commented Sep 29, 2022

Adds support for:

  • disabling/enabling the wifi auto-connect "feature" of the esp8266 (WLAN.config(auto_connect=True/False)); and
  • setting the reconnect policy for the esp8266 after disconnecting from wifi (WLAN.config(reconnects=xx)).

Motivation
The auto-connect feature is regarded by some as a mis-feature of the esp8266 and is one source of incompatible behaviour for code running on esp32 and esp8266. The auto_connect=False option allows users to ensure their esp8266 device's behaviour is deterministically derived from startup code. The reconnects option provides similar (but not the same) functionality to the reconnects opton on ESP32.

The semantics of the reconnects option differ from the esp32 in important ways:

  • reconnects=0:
    • ESP32 and ESP8266: No attempt is made to reconnect after disconnection from AP
  • reconnects>=1:
    • ESP32: Sets the maximum number of times the device will attempt to reconnect to AP
    • ESP8266: Sets the number of times device will attempt to retry dhcp after disconnecting.

Note: WLAN.config("reconnects") is not supported since the esp8266 SDK provide no mechanism for querying the current settings.

This PR adds:

  • WLAN.config(auto_connect=True/False) to enable/disable the ESP8266 from automatically connecting to wifi networks after WLAN.active(True).
  • WLAN.config(reconnects=xx) where xx is an integer to limit the number of times to attempt to reconnect after becoming disconnected from a wifi access point.

@glenn20 glenn20 force-pushed the esp8266-feature-reconnects branch from 325a7e2 to e5a6b89 Compare April 2, 2023 05:01
@glenn20
Copy link
Contributor Author

glenn20 commented Apr 2, 2023

Rebased against main to resolve conflicts.

@AmirHmZz
Copy link
Contributor

AmirHmZz commented May 6, 2023

I think it's a good time for @dpgeorge to review this PR too...

Adds:
- WLAN.config(auto_connect=False) to stop the ESP8266 from
  automatically connecting to wifi networks after bootup.

- WLAN.config(reconnects=X) to limit the number of times to
  attempt to reconnect after becoming disconnected from a wifi
  access point.
@inovatorius
Copy link

@glenn20 Thank you for such a great work!

But still, is it WLAN.config('autoconnect') or WLAN.config('auto_connect') because for the first one I get ValueError: unknown config param and the second works just fine.

@glenn20
Copy link
Contributor Author

glenn20 commented Jun 19, 2023

But still, is it WLAN.config('autoconnect') or WLAN.config('auto_connect') because for the first one I get ValueError: unknown config param and the second works just fine.

Ah - thanks for picking up on this. It is indeed "auto_connect". I will fix the description above to match.

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

Successfully merging this pull request may close these issues.

4 participants