Skip to content

Latest commit

 

History

History
42 lines (35 loc) · 1005 Bytes

231020.wifi-cycler.md

File metadata and controls

42 lines (35 loc) · 1005 Bytes

2023-10-20

https://discordapp.com/channels/918498540232253480/918498540232253483/1164633871799824455

wifi-cycler.toit

''' 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." '''