コード例 #1
0
ファイル: network.py プロジェクト: bourne-h/AliOS-Things
    def connect(self, data):
        """
        连接网络

        :param data(dict): data的key信息如下

            .. list-table::

                * - 属性
                  - 类型
                  - 必填
                  - 说明
                * - ssid
                  - 字符串
                  - 必填
                  - 需要连接的wifi热点名称
                * - password
                  - 字符串
                  - 必填
                  - 需要连接的wifi密码


            使用示例::

                # -*- coding: UTF-8 -*-
                import network
                net =  network.NetWorkClient()
                net.connect({
                        'ssid' : 'KIDS' ,
                        'password' : '12345678'
                    }
                )
        """
        if isinstance(data, dict):
            pass
        else:
            raise ValueError("connect func param must be dict")

        if not 'ssid' in data:
            raise ValueError('connect : param must have key "ssid"')
        elif self.__str_is_empty(data['ssid']):
            raise ValueError("ssid wrong")

        if not 'password' in data:
            raise ValueError('connect : param must have key "password"')
        elif self.__str_is_empty(data['password']):
            raise ValueError("password wrong")
        nm.connect(data['ssid'], data['password'])
コード例 #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
ファイル: network.py プロジェクト: samxxzr/AliOS-Things
    def connect(self, data):
        """
        连接网络

        **入参**

        data类型是字典,字典的key信息如下

            - ssid : 必选,值是字符串
            - password : 必选,值是字符串


        使用示例::

            # -*- coding: UTF-8 -*-
            import network
            net =  network.NetWorkClient()
            net.connect({
                    'ssid' : 'KIDS' ,
                    'password' : '12345678'
                }
            )
        """
        if isinstance(data, dict):
            pass
        else:
            raise ValueError("connect func param must be dict")

        if not 'ssid' in data:
            raise ValueError('connect : param must have key "ssid"')
        elif self.__str_is_empty(data['ssid']):
            raise ValueError("ssid wrong")

        if not 'password' in data:
            raise ValueError('connect : param must have key "password"')
        elif self.__str_is_empty(data['password']):
            raise ValueError("password wrong")
        nm.connect(data['ssid'], data['password'])
コード例 #4
0
ファイル: main.py プロジェクト: bourne-h/AliOS-Things
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
    else:
        print('Wait for wifi connected')
        time.sleep(1)

if nm.getStatus():
    print('DeviceIP:' + nm.getInfo()['IP'])
else:
    print('DeviceIP:get failed')
コード例 #5
0
def connect_wifi():
    nm.init()
    nm.connect("KIDS", "12345678")