← index #12315PR #9460
Related · high · value 3.234
QUERY · ISSUE

WLAN.config(reconnects) and WLAN.status() doesn't work as intended

openby inovatoriusopened 2023-08-27updated 2023-08-28
bug

Hello!

MicroPython v1.20.0 on ESP8266.

Example:

import network
from time import sleep_ms

sleep_ms(3000)

sta = network.WLAN(network.STA_IF)
sta.active(True)

while not sta.active():
    sleep_ms(100)

_wlan_status = sta.status()
sta.config(auto_connect=False, reconnects=0)  # Number of reconnect attempts to make (integer, 0=none, -1=unlimited)
sta.connect('MyAPP')

while True:
    _wlan_status = sta.status()
    if _wlan_status == 0:
        print('IDLE')
    if _wlan_status == 1:
        print('CONNECTING')
    if _wlan_status == 2:
        print('WRONG PASSWORD')
    if _wlan_status == 3:
        print('AP NOT FOUND')
    if _wlan_status == 4:
        print('CONNECTION FAILED')
    if _wlan_status == 5:
        print('SUCCESS')
    sleep_ms(1000)
  1. With sta.config(reconnects=-1) the result is AP NOT FOUND, while with sta.config(reconnects=0) it is CONNECTING.

  2. When we are connecting to the non-existing AP, we receive AP NOT FOUND, while connecting with wrong password we get CONNECTION FAILED.

  3. I am unable to capture WRONG PASSWORD when using wrong password.

PR associated with this is https://github.com/micropython/micropython/pull/9460

CANDIDATE · PULL REQUEST

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

openby glenn20opened 2022-09-29updated 2023-06-19
port-esp8266

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied