-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwifi3.py
More file actions
50 lines (39 loc) · 1.02 KB
/
wifi3.py
File metadata and controls
50 lines (39 loc) · 1.02 KB
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
import network
from time import sleep
from machine import reset
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.config(pm=0xa11140)
ip = ''
ssid = ''
def connect_to_wlan(w):
global wlan, ip, ssid
for s in w:
wlan.connect(s["ssid"], s["password"])
counter = 1
while not connected_to_wlan() and counter < 4:
print('Waiting for connection...', s["ssid"], counter)
sleep(3)
counter += 1
ip = wlan.ifconfig()[0]
ssid = s["ssid"]
if counter == 4 or ip == '0.0.0.0' or wlan.status() != 3:
disconnect_from_wlan()
else:
print(ssid, " ", wlan.ifconfig())
print(f'Connected on {ip}')
return
print("No wifi connection made")
reset()
def which_wlan():
global wlan
return wlan.ifconfig()
def which_ssid():
global ssid
return ssid
def disconnect_from_wlan():
global wlan
wlan.disconnect()
def connected_to_wlan():
global wlan
return wlan.isconnected()