You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ESP32调用wlan.status()返回1010而非1-5导致连接报错

ESP32 WiFi连接代码报错:RuntimeError: network connection failed,wlan.status()返回1010但isconnected()为True

在ESP32设备上通过Thonny IDE运行以下代码时,始终触发RuntimeError: network connection failed错误:

import utime
import network

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("Dream Net R-632", "07132711")


max_wait = 10
while max_wait > 0:
    """
        0   STAT_IDLE -- no connection and no activity,
        1   STAT_CONNECTING -- connecting in progress,
        -3  STAT_WRONG_PASSWORD -- failed due to incorrect password,
        -2  STAT_NO_AP_FOUND -- failed because no access point replied,
        -1  STAT_CONNECT_FAIL -- failed due to other problems,
        3   STAT_GOT_IP -- connection successful.
    """
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print('waiting for connection... ' + str(max_wait))
    utime.sleep(1)


if wlan.status() != 3:
    raise RuntimeError('network connection failed')
else:
    print('wlan connected')
    status = wlan.ifconfig()
    print('IP address = ' + status[0])
    print('subnet mask = ' + status[1])
    print('gateway  = ' + status[2])
    print('DNS server = ' + status[3])

实际测试发现,WiFi已成功连接(调用wlan.isconnected()返回True),但wlan.status()返回值为1010,并非代码注释中列出的状态值范围,导致代码中的连接判断逻辑出错。交互示例如下:

>>> wlan.active(True)
True
>>> wlan.status()
1010
>>> 

已确认SSID和密码正确,问题仅出在wlan.status()返回1010这一异常值上。

内容的提问来源于stack exchange,提问作者Shaair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 01:05:10