1#!/usr/bin/env python
2# -*- encoding: utf-8 -*-
3'''
4@File       :    ConnectWifi.py
5@Description:    file description
6@Date       :    2021/04/22 14:48:16
7@Author     :    guoliang.wgl
8@version    :    1.0
9'''
10import network
11import utime as time
12import sys
13
14
15net = network.NetWorkClient()
16connected = net.getStatus()
17
18def on_wifi_connected(status):
19    global connected
20    print('*******wifi connected*********')
21    connected = 5
22
23if  connected != 5 :
24    net.on(1,on_wifi_connected)
25    if(len(sys.argv) == 3):
26        net.connect({'ssid':sys.argv[1],'password':sys.argv[2]})
27    else:
28        net.connect("KIDS","12345678")
29
30while True :
31    if connected == 5:
32        break
33    else:
34        print('Wait for wifi connected')
35        time.sleep(1)
36
37if net.getStatus() == 5 :
38    print('DeviceIP:' + net.getInfo()['IP'])
39else:
40    print('DeviceIP:get failed')
41
42print("ConnectWifi finished")
43