← index #12315Issue #12930
Related · high · value 1.568
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 · ISSUE

esp32: When network.STAT_NO_AP_FOUND and network.STAT_WRONG_PASSWORD occurred?

closedby IhorNehrutsaopened 2023-11-09updated 2023-11-23
bug

boot.py is:

print('\nboot.py')

from machine import reset

import network
wlan = network.WLAN(network.STA_IF)

def do_connect(ssid, password):
    wlan_status = wlan.status()
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        print('wlan:', wlan.ifconfig(), wlan.isconnected(), wlan.status())
        wlan.connect(ssid, password)
        while not wlan.isconnected():
            if wlan_status != wlan.status():
                print('wlan status', wlan_status, 'changed to', wlan.status())
                wlan_status = wlan.status()
    print('wlan:', wlan.ifconfig(), wlan.isconnected(), wlan.status())
>>> reset()
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4728
load:0x40078000,len:14876
ho 0 tail 12 room 4
load:0x40080400,len:3368
entry 0x400805cc

boot.py
MicroPython-1.21.0-xtensa-IDFv5.0.2-with-newlib4.1.0
('newlib', '4.1.0')
GCC 11.2.0
MicroPython v1.21.0 on 2023-10-05; Generic ESP32 module with ESP32
Type "help()" for more information.

When the ssid and password are correct, the connection is established.

>>> do_connect('right_ssid', 'right_password')
connecting to network...
wlan: ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0') False 1000
wlan status 1000 changed to 1001
wlan: ('192.168.3.230', '255.255.255.0', '192.168.3.1', '8.8.8.8') True 1010

If the ssid is wrong, the connection is not established.
I expected wlan.status() to return network.STAT_NO_AP_FOUND, but it doesn't.

>>> do_connect('wrong_ssid', 'password')
connecting to network...
wlan: ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0') False 1000
wlan status 1000 changed to 1001

If the ssid is correct and password is wrong, the connection is not established.
I expected wlan.status() to return network.STAT_WRONG_PASSWORD, but it doesn't.
E (41882) wifi:Set status to INIT reported infinity times.

>>> do_connect('right_ssid', wrong_password')
connecting to network...
wlan: ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0') False 1000
wlan status 1000 changed to 1001
E (41882) wifi:Set status to INIT
E (44322) wifi:Set status to INIT
E (52192) wifi:Set status to INIT
E (54632) wifi:Set status to INIT
...

for reference:

>>> network.STAT_IDLE
1000
>>> network.STAT_CONNECTING
1001
>>> network.STAT_GOT_IP
1010
>>> network.STAT_NO_AP_FOUND
201
network.STAT_WRONG_PASSWORD
202

wlan.status() must return
network.STAT_NO_AP_FOUND if ssid is wrong and
network.STAT_WRONG_PASSWORD if password is wrong

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