micropython网络配置
物联网 micropython
2020年6月17日

连接wifi

# utils.py
import network

class Network:
    def __init__(self):
        self.sta_if = network.WLAN(network.STA_IF)
        self.ap_if = network.WLAN(network.AP_IF)
        # 禁用ap
        self.ap_if.active(False)

    def sta_connect(self, ssid, password):
        if not self.sta_if.isconnected():
            print('connecting to network...')
            self.sta_if.active(True)
            self.sta_if.connect(ssid, password)
            while not self.sta_if.isconnected():
                pass
        print('network config:', self.sta_if.ifconfig())

开启远程连接

import webrepl_setup


WebREPL daemon auto-start status: disabled

Would you like to (E)nable or (D)isable it running on boot?
(Empty line to quit)
> E
To enable WebREPL, you must set password for it
New password (4-9 chars): yourpassword
Confirm password: yourpassword
Changes will be activated after reboot
Would you like to reboot now? (y/n) y

通过mpfshell进行连接

pip install mpfshell

mpfshell ws:192.168.1.199,youpassword

最后修改于: 2023年8月9日 17:05