-
Notifications
You must be signed in to change notification settings - Fork 1
/
netconn.py
43 lines (38 loc) · 1.27 KB
/
netconn.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
import network
import utime as time
ssid = ["ssid_1","ssid_2"]
password = ["password_1","password_2"]
networks = [ssid,password]
def connect():
#connect to local wireless network
station = network.WLAN(network.STA_IF)
def __conn__(ssid, password):
if not station.isconnected():
print("Attempting connection to '%s'..." % ssid)
# Connect
station.connect(ssid, password)
# Wait till connection is established
for i in range(10):
if station.isconnected():
#wlan.ifconfig(ipaddress, netmask, gateway, dns)
break
time.sleep_ms(500)
else:
return None
print("Now connected to '%s'." % ssid)
else:
print('Already Connected.')
return station
print("length of networks is: ", len(networks[0]))
for x in range(len(networks[0])):
station.active(True)
#disconnect in case we are already connected
station.disconnect()
wlan = __conn__(networks[0][x],networks[1][x])
if wlan:
ipData = station.ifconfig()
print(ipData)
return ipData[0], ipData[2]
break
else:
print("No network found.")