mirror of
https://github.com/c0de-archive/pixoPython.git
synced 2024-12-22 05:12:41 +00:00
Connect to stored list of networks
This commit is contained in:
parent
1d5718434d
commit
e01d14d076
17
pixo/wifi.py
17
pixo/wifi.py
@ -20,18 +20,19 @@ def is_connected(interface):
|
|||||||
if interface == AP_IF:
|
if interface == AP_IF:
|
||||||
return (len(interface.status('stations')) > 0)
|
return (len(interface.status('stations')) > 0)
|
||||||
|
|
||||||
def connect(interface, interface_name):
|
def connect(interface, interface_name, ssid, password):
|
||||||
print("Configuring %s interface with credentials from creds.py" % interface_name)
|
print("Configuring %s interface with credentials from creds.py" % interface_name)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
# Start the interface if it's not already
|
# Start the interface if it's not already
|
||||||
interface.active(True)
|
interface.active(True)
|
||||||
|
|
||||||
|
# Connect to the network
|
||||||
if interface == STA_IF:
|
if interface == STA_IF:
|
||||||
STA_IF.connect(creds.WIFI_SSID, creds.WIFI_PASSWORD)
|
STA_IF.connect(ssid, password)
|
||||||
selected_color = (200, 40, 40)
|
selected_color = (200, 40, 40)
|
||||||
elif interface == AP_IF:
|
elif interface == AP_IF:
|
||||||
AP_IF.config(essid=creds.AP_SSID, password=creds.AP_PASSWORD)
|
AP_IF.config(essid=ssid, password=password)
|
||||||
selected_color = (20, 10, 230)
|
selected_color = (20, 10, 230)
|
||||||
|
|
||||||
while not interface.isconnected():
|
while not interface.isconnected():
|
||||||
@ -44,9 +45,13 @@ def connect(interface, interface_name):
|
|||||||
if is_connected(interface):
|
if is_connected(interface):
|
||||||
Pixo().fill_image(WIFI_IMG, False).force_color((40, 200, 40))
|
Pixo().fill_image(WIFI_IMG, False).force_color((40, 200, 40))
|
||||||
|
|
||||||
# TODO: iterate over known access points and save multiple passwords
|
|
||||||
if not STA_IF.isconnected():
|
if not STA_IF.isconnected():
|
||||||
connect(STA_IF, 'Standard')
|
for network in creds.WIFI_NETWORKS:
|
||||||
|
if STA_IF.isconnected():
|
||||||
|
break
|
||||||
|
connect(STA_IF, 'Standard',
|
||||||
|
creds.WIFI_NETWORKS[network][0],
|
||||||
|
creds.WIFI_NETWORKS[network][1])
|
||||||
|
|
||||||
# We check this twice to enable AP mode if we failed to connect
|
# We check this twice to enable AP mode if we failed to connect
|
||||||
# Normally this happens if the password has been misconfigured,
|
# Normally this happens if the password has been misconfigured,
|
||||||
@ -58,4 +63,4 @@ if not STA_IF.isconnected():
|
|||||||
# method to try connecting again (after `creds.py` has been fixed)
|
# method to try connecting again (after `creds.py` has been fixed)
|
||||||
STA_IF.active(False)
|
STA_IF.active(False)
|
||||||
|
|
||||||
connect(AP_IF, 'Access Point')
|
connect(AP_IF, 'Access Point', creds.AP_SSID, creds.AP_PASSWORD)
|
Loading…
Reference in New Issue
Block a user