Last active
October 19, 2023 19:15
-
-
Save floitsch/373e2814c341fa9dc8ee759ca4d257dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net | |
import net.wifi | |
CREDENTIALS ::= [ | |
[ "ssid1", "password" ], | |
[ "ssid2", "password" ] | |
] | |
attempt-connection [block] -> bool: | |
network/net.Interface? := null | |
exception := catch: network = block.call | |
if network: | |
print "Configuration works" | |
network.close | |
return true | |
print "Configuration seems to be broken." | |
print "Exception: $exception" | |
return false | |
main: | |
print "Trying to connect to saved configuration." | |
succeeded := attempt-connection: net.open | |
if not succeeded: | |
print "Attempting to connect to stored credentials." | |
for i := 0; i < CREDENTIALS.size; i++: | |
current := CREDENTIALS[i] | |
ssid := current[0] | |
password := current[1] | |
succeeded = attempt-connection: wifi.open --ssid=ssid --password=password --save | |
if succeeded: | |
break | |
if not succeeded: | |
print "No configuration worked." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment