import network
import apitime
import time
# -----------------------------------------------------------------------------------
#Access data for the WLAN network
ssid = "Wokwi-GUEST"
password = ""
# -----------------------------------------------------------------------------------
# Establishing a WLAN connection
def wlanConnect():
wlan = network.WLAN(network.STA_IF)
#wlan.active(False)
#time.sleep(0.5)
wlan.active(True)
time.sleep(0.5)
wlan.connect(ssid, password)
print("\r\n" + "Connecting to WLAN")
while not wlan.isconnected() and wlan.status() >= 0:
print(".", end="")
time.sleep(1)
print("\r\n" + "Connected to WLAN")
print(wlan.ifconfig())
# -----------------------------------------------------------------------------------
# Calling the wlan() function
wlanConnect()
# -----------------------------------------------------------------------------------
# Main function
def main():
# Get time from API and set RTC (See zones.py and copy/past your zone)
# apitime.settime("timezone = eg. UTC, Europe/Berlin"), (autoDST = True, False),
# (printOut = True, False), (offset = in sec.)
apitime.settime("Europe/Berlin", True, True)
# Output local time
print(time.localtime())
# -----------------------------------------------------------------------------------
# Calling the main() function
while True:
main()
# IMPORTANT: Insert a pause of 60 seconds before
# asking the server for the current time again.
# The server rejects the connection if
# the request interval is too short.
time.sleep(60)