Programming with MicroPython: Network Time Protocol
Last updated
Last updated
Import the Library to make use of its functions.
from future import *
from machine import RTC
import ntptime
rtc = RTC()
ntptime.settime(zone=8)
Parameter zone is for GMT, default is 8.
rtc.datetime()
Returns a list containing the current time, [year, month, day, week, hour, minute, second].
# Displays the current time
#/bin/python
from future import *
import ntptime
from machine import RTC
rtc = RTC()
from time import sleep
wifi.connect(str("wifi"), "password")
ntptime.settime(int(8))
screen.sync = 0
while True:
screen.fill((0, 0, 0))
screen.text("Time:",5,10,2,(0, 119, 255))
screen.text(str(rtc.datetime()[int(4)])+str(str(":")+str(rtc.datetime()[int(5)])),5,40,3,(0, 119, 255))
screen.refresh()
sleep(1)