Skip to content

Instantly share code, notes, and snippets.

@floitsch
Last active October 19, 2023 19:15
Show Gist options
  • Save floitsch/373e2814c341fa9dc8ee759ca4d257dd to your computer and use it in GitHub Desktop.
Save floitsch/373e2814c341fa9dc8ee759ca4d257dd to your computer and use it in GitHub Desktop.
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