import network
import time
from machine import Timer
#========================= WiFi Setup ============================
# This function is used to setup the WiFi connection
# This function returns the 'wlan' object so it can be passed
# to getConfig() and the values printed out
# This can take a while :(
#=================================================================
def setupWiFi():
print("Connecting to WiFi ", end="")
# Create the Wireless Nic object
wnic = network.WLAN(network.STA_IF)
# Enable the Nic
wnic.active(True)
# Connect to the virtual access point
wnic.connect("Wokwi-GUEST", "")
# This prints the dots out accross the screen while waiting for
# WiFi to connect
while not wnic.isconnected():
print(".", end="")
time.sleep(0.1)
# This prints after a successful connection
print(" Connected!\n")
return wnic
def setup(setup_timer):
# This is just here to clear the console buffer
print("")
# Setup WiFi
setupWiFi()
# This calls the setup() function one time when the application starts after 3 seconds
setup_timer = Timer(mode=Timer.ONE_SHOT, period=3000, callback=setup)