Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active April 1, 2024 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todbot/0a883c7321ea49aaff768b8ff118b562 to your computer and use it in GitHub Desktop.
Save todbot/0a883c7321ea49aaff768b8ff118b562 to your computer and use it in GitHub Desktop.
Make an internet clock with CircuitPython using WorldTimeAPI.org
# Make an internet clock with CircuitPython using WorldTimeAPI.org
# 31 Mar 2024 - @todbot / Tod Kurt
# Use resulting strings for displaying on a display of some kind
import os, time
import wifi
import adafruit_requests
import socketpool
import ssl
time_url = "http://worldtimeapi.org/api/ip"
print("connecting to:",os.getenv('WIFI_SSID'))
wifi.radio.connect(ssid=os.getenv('WIFI_SSID'),
password=os.getenv('WIFI_PASSWORD'))
print("connected.")
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
while True:
response = requests.get(time_url)
timedata = response.json()
date_str, time_str = timedata['datetime'].split('T')
time_str, frac_secs_str = time_str.split('.')
print(time.monotonic(), ": date:", date_str, "time:",time_str)
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment