示例#1
0
    def getStatus(self):
        """

        获取当前网络状态

        :param 空:
        :returns: 

          .. list-table::

                * - 返回值
                  - 连接状态
                * - 0
                  - 断开连接中
                * - 1
                  - 断开连接
                * - 2
                  - 连接中
                * - 3
                  - 连接成功
                * - 4
                  - 获取ip中
                * - 5
                  - 获取ip成功
                * - 6
                  - 连接失败
                * - 7
                  - 位置状态


          - ``True``  已连接
          - ``False`` 未连接

        """
        return nm.getStatus()
示例#2
0
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地址信息
示例#3
0
    def getStatus(self):
        """

        获取当前网络状态

          - ``True``  已连接
          - ``False`` 未连接

        """
        return nm.getStatus()
示例#4
0
    def getStatus(self):
        """

        获取当前网络状态

        :param 空:
        :returns: 

          - ``True``  已连接
          - ``False`` 未连接

        """
        return nm.getStatus()
示例#5
0
#!/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