MicroPython ESP32 手动入网配置调试过程

MicroPython ESP32 手动入网配置调试过程


  • 本实验基于Thonny平台

Shell调试窗口入网过程

MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32

Type "help()" for more information.
>>> import network
>>> wlan = network.WLAN(network.STA_IF)
>>> wlan.active(True)
True
>>> wlan.scan()
[(b'MERCURY_D268G', b'D\xf9q\xdb\x87\xd9', 11, -25, 4, False), (b'MERCURY_Guest', b'F\xf9q\xdb\x87\xd9', 11, -25, 4, False), (b'MERCURY_2.4G_135E', b'\x90v\x9fP\x13^', 1, -54, 4, False), (b'CMCC-DyVv', b'\xa0\x91\xc8\xd1\xce\x90', 5, -58, 4, False), (b'MERCURY_2.4G_135F', b'\x90v\x9fP\x13_', 1, -82, 4, False)]
>>> wlan.isconnected()
False
>>> wlan.connect('MERCURY_D268G', 'pba5ayzk')
>>> wlan.isconnected()
True
>>> print('network config:', wlan.ifconfig())
network config: ('192.168.0.110', '255.255.255.0', '192.168.0.1', '192.168.0.1')

入网示例程序代码

MicroPython ESP32 手动入网配置调试过程_第1张图片

from machine import Pin
import utime
led = Pin(2, Pin.OUT) #用machine模块的pin功能设置引脚2为输出。
def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('MERCURY_D268G', 'pba5ayzk')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
 
def blink():
    led.value(1) #将引脚2设置为高电平
    utime.sleep(2) # 延时1秒
    led.value(0) #将引脚2设置为低电平
    utime.sleep(2)
    print('perseverance')

do_connect()    
while True:   
    blink()
        

  • 可以将程序固化到板子上。

选择MicroPython设置以:main.py名字进行保存即可实现上电自动跑main.py

MicroPython ESP32 手动入网配置调试过程_第2张图片

你可能感兴趣的:(#,MicroPython,for,ESP32,MicroPython,ESP32,esp32入网)