Skip to content

Commit 4b2aa95

Browse files
authored
Update SimpleWebClockWithTimerUsingWebAPI.py
1 parent 2a9e7ab commit 4b2aa95

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

SimpleWebClockWithTimerUsingWebAPI.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
SCL = 5
77
SDA = 4
88

9-
import network, urequests, utime, ssd1306, gc
9+
import network, requests, time, ssd1306, gc
1010
from machine import Pin, SoftI2C, Timer, RTC
1111

1212
gc.enable()
@@ -33,19 +33,19 @@
3333
def rtcUpdate(timer):
3434
while True:
3535
try:
36-
response = urequests.get('http://worldtimeapi.org/api/ip')
36+
response = requests.get('http://worldtimeapi.org/api/ip')
3737
if response.status_code == 200:
3838
parsed = response.json()
3939
# parsed['unixtime']: local unixtime since 1970/01/01 00:00:00)
4040
# parsed['raw_offset']: timezone hour offset
4141
# 946684800: unixtime of 2020/01/01 00:00:00 (system start time on MicroPython)
4242
# generate datetime tuple based on these information
43-
dt = utime.localtime(parsed['unixtime'] + parsed['raw_offset'] - 946684800)
43+
dt = time.localtime(parsed['unixtime'] + parsed['raw_offset'] - 946684800)
4444
# rtc.datetime((year, month, day, weekday, hour, minute, second, microsecond))
4545
rtc.datetime((dt[0], dt[1], dt[2], dt[6], dt[3], dt[4], dt[5], 0))
4646
break
4747
except:
48-
utime.sleep(10) # try again if failed
48+
time.sleep(10) # try again if failed
4949

5050
# display update function
5151
def clockUpdate(timer):

0 commit comments

Comments
 (0)