-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwificonnect.py
61 lines (44 loc) · 1.16 KB
/
wificonnect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import network
import time
wlan = network.WLAN(network.STA_IF)
def start():
wlan.active(True)
if wlan.isconnected():
wlan.disconnect()
print("WLAN start successed")
def scan():
wlan_imformation = wlan.scan()
print("WLAN scan successed")
return wlan_imformation
def connect(ssid, password, timeout=10000):
if wlan.isconnected():
wlan.disconnect()
timeout = timeout / 1000 # 设置超时时间为30秒
start_time = time.time()
print("WLAN Connecting")
wlan.connect(ssid, password)
while not wlan.isconnected():
if wlan.isconnected():
break
if time.time() - start_time > timeout:
print("WLAN Connect Timeout")
close()
return
if wlan.isconnected():
print("WLAN Connect Successd")
else:
print("WLAN Connect Failed")
close()
def close():
if wlan.isconnected():
wlan.disconnect()
wlan.active(False)
def status():
if wlan.isconnected():
return True
return False
def info():
if not wlan.isconnected():
print('wifi not connected')
return
return wlan.ifconfig()