def get_wifi_status(): nm.init() wifi_connected = nm.getStatus() nm.disconnect() print("start to connect " , wifiSsid) nm.connect(wifiSsid, wifiPassword) # 连接到指定的路由器(路由器名称为wifiSsid, 密码为:wifiPassword) while True : if wifi_connected == 5: # nm.getStatus()返回5代表连线成功 break else: wifi_connected = nm.getStatus() # 获取Wi-Fi连接路由器的状态信息 utime.sleep(0.5) print("wifi_connected:", wifi_connected) # utime.sleep(5) print("Wi-Fi connected") print('DeviceIP:' + nm.getInfo()['ip']) # 打印Wi-Fi的IP地址信息
#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @File : ConnectWifi.py @Description: file description @Date : 2021/04/22 14:48:16 @Author : guoliang.wgl @version : 1.0 ''' import netmgr as nm import utime as time import sys nm.init() connected = nm.getStatus() def on_wifi_connected(status): global connected print('*******wifi connected*********') connected = True if not connected: nm.register_call_back(1,on_wifi_connected) if(len(sys.argv) == 3): nm.connect(sys.argv[1],sys.argv[2]) else: nm.connect("KIDS","12345678") while True : if connected: break
def connect_wifi(): nm.init() nm.connect("KIDS", "12345678")
def __init__(self): nm.init()
def getinstance(): if cls not in instances: instances[cls] = cls(*args, **kw) nm.init() return instances[cls]