<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to make RTC clock with NTP]]></title><description><![CDATA[<p dir="auto">How to make RTC clock with NTP Sync for M5StickC in in python (UIflow 1.4.4) ?<br />
the code below gives an error "RTC' object has no atribute 'ntp_sync"</p>
<p dir="auto">import machine<br />
import utime</p>
<p dir="auto">rtc = machine.RTC()<br />
rtc.ntp_sync(server="<a href="http://hr.pool.ntp.org" target="_blank" rel="noopener noreferrer nofollow ugc">hr.pool.ntp.org</a>", tz="CET-1CEST")<br />
rtc.synced()<br />
True<br />
utime.gmtime()<br />
(2018, 1, 29, 16, 3, 18, 2, 29)<br />
utime.localtime()<br />
(2018, 1, 29, 17, 3, 30, 2, 29)</p>
]]></description><link>https://community.m5stack.com/topic/1625/how-to-make-rtc-clock-with-ntp</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 02:46:11 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1625.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 16 Jan 2020 20:37:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to make RTC clock with NTP on Thu, 01 Apr 2021 08:13:00 GMT]]></title><description><![CDATA[<p dir="auto">Thx <a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> - only that example does not appear to be applicable to the M5StickC.</p>
]]></description><link>https://community.m5stack.com/post/13343</link><guid isPermaLink="true">https://community.m5stack.com/post/13343</guid><dc:creator><![CDATA[dionw]]></dc:creator><pubDate>Thu, 01 Apr 2021 08:13:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Sun, 28 Mar 2021 12:33:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dionw" aria-label="Profile: dionw">@<bdi>dionw</bdi></a> said in <a href="/post/13281">How to make RTC clock with NTP</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukasmaximus" aria-label="Profile: lukasmaximus">@<bdi>lukasmaximus</bdi></a> I'm keen to see this working as well. When do you think it might be possible for the NTP RTC example uiFlow block <a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> mentioned<br />
he had uploaded to be available?</p>
</blockquote>
<p dir="auto">Not Sure what happened to it but the example file has been uploaded to github<br />
<a href="https://github.com/Ajb2k3/UIFlowHandbook/blob/master/NTP_RTC.m5f" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/Ajb2k3/UIFlowHandbook/blob/master/NTP_RTC.m5f</a></p>
]]></description><link>https://community.m5stack.com/post/13282</link><guid isPermaLink="true">https://community.m5stack.com/post/13282</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Sun, 28 Mar 2021 12:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Sun, 28 Mar 2021 11:34:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukasmaximus" aria-label="Profile: lukasmaximus">@<bdi>lukasmaximus</bdi></a> I'm keen to see this working as well. When do you think it might be possible for the NTP RTC example uiFlow block <a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> mentioned he had uploaded to be available?</p>
]]></description><link>https://community.m5stack.com/post/13281</link><guid isPermaLink="true">https://community.m5stack.com/post/13281</guid><dc:creator><![CDATA[dionw]]></dc:creator><pubDate>Sun, 28 Mar 2021 11:34:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Sat, 27 Feb 2021 19:40:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukasmaximus" aria-label="Profile: lukasmaximus">@<bdi>lukasmaximus</bdi></a> Why is it still not fixed?</p>
]]></description><link>https://community.m5stack.com/post/12706</link><guid isPermaLink="true">https://community.m5stack.com/post/12706</guid><dc:creator><![CDATA[sj3fk3]]></dc:creator><pubDate>Sat, 27 Feb 2021 19:40:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Thu, 14 Jan 2021 08:26:55 GMT]]></title><description><![CDATA[<p dir="auto">I recently uploaded an NTP RTC example for UIFLow 1.7.<br />
Where has that gone?<br />
<img src="/assets/uploads/files/1610612811375-rtcexamp.png" alt="0_1610612797712_RTCexamp.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.m5stack.com/post/11739</link><guid isPermaLink="true">https://community.m5stack.com/post/11739</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Thu, 14 Jan 2021 08:26:55 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Wed, 13 Jan 2021 16:31:32 GMT]]></title><description><![CDATA[<p dir="auto">Same here. The M5 Docs are a nightmare!!<br />
On every documentation, the syntax is wrong, and not work correctly!<br />
😒</p>
]]></description><link>https://community.m5stack.com/post/11737</link><guid isPermaLink="true">https://community.m5stack.com/post/11737</guid><dc:creator><![CDATA[TheAlphaGhost]]></dc:creator><pubDate>Wed, 13 Jan 2021 16:31:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Fri, 14 Feb 2020 06:05:56 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, the last few lines should read:</p>
<pre><code>CurrentYear   = int(RightNow[RTC_YYYY])
CurrentMonth  = int(RightNow[RTC_MM])
CurrentDay    = int(RightNowRTC_DD])
CurrentHour   = int(RightNow[RTC_HH])
CurrentMinute = int(RightNow[RTC_MN])
CurrentSecond = int(RightNow[RTC_SS])
</code></pre>
<p dir="auto">Sorry, this is my first MicroPython program and just learning it.<br />
Ray</p>
]]></description><link>https://community.m5stack.com/post/7392</link><guid isPermaLink="true">https://community.m5stack.com/post/7392</guid><dc:creator><![CDATA[raystdenis]]></dc:creator><pubDate>Fri, 14 Feb 2020 06:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Fri, 14 Feb 2020 05:23:37 GMT]]></title><description><![CDATA[<p dir="auto">Got tired of waiting for M5Stack MicroPython to support rtc.ntp_sync, so I came up with a simple workaround, assuming you have access to a webserver:</p>
<p dir="auto">On your webserver, just create a tiny datetime.php file as follows:</p>
<hr />
<blockquote></blockquote>
<p dir="auto">&lt;html&gt;&lt;body&gt;<br />
&lt;?php echo '[' . getDatetimeNow() . ']';</p>
<p dir="auto">function getDatetimeNow() {<br />
$tz_object = new DateTimeZone('Canada/Pacific');<br />
$datetime = new DateTime();<br />
$datetime-&gt;setTimezone($tz_object);<br />
return $datetime-&gt;format('Y-m-d\ H:i:s');<br />
}<br />
?&gt;<br />
&lt;/body&gt;&lt;/html&gt;</p>
<hr />
<p dir="auto">Change the TimeZone to your own timezone.<br />
When this PHP code runs, it simply takes the webserver's internal date and time (which should be fairly accurate) and displays the text [yyyy-mm-dd hh:mm:ss]</p>
<p dir="auto">Now in your MicroPython code, do the following:</p>
<pre><code>from micropython import const
from m5stack import *
from m5ui import *
from uiflow import *
import utime as time
import machine
import urequests
import wifiCfg

RTC_YYYY = const(0)
RTC_MM   = const(1)
RTC_DD   = const(2)
RTC_HH   = const(4)
RTC_MN   = const(5)
RTC_SS   = const(6)

WIFI_SSID      = 'YourSSID'
WIFI_PASSWORD  = 'YourPassword'
URL            = 'http://api.pushingbox.com/pushingbox?devid=v883AAC5A2DE4A5A&amp;location='
DATETIME_URL   = 'http://stdenissoftware.com/datetime.php'


#==================================================================
# Set internal RTC clock based on calling a URL that returns the current local time
# as '[yyyy-mm-dd hh:mm:ss]'. Function must be connected to internet.
# Parameters:
#   WIFI_SSID: the SSID to connect to
#   WIFI_PASSWORD: Wifi Password
#   DATETIME_URL: the URL to call to return the current time 
def setRTC(WIFI_SSID,WIFI_PASSWORD,DATETIME_URL):
  rtc = machine.RTC()
  while wifiCfg.wlan_sta.isconnected() != True:
    wifiCfg.doConnect(WIFI_SSID,WIFI_PASSWORD)
    if wifiCfg.wlan_sta.isconnected() != True:
      time.sleep(1)
    #end if
  #wend
  if wifiCfg.wlan_sta.isconnected():
    #lblWiFi.setText('WiFi Connected')
    try:
      req = urequests.request(method='GET', url=DATETIME_URL,headers='')
      httpData = req.text
      iPos1 = httpData.find("[")
      iPos2 = httpData.find("]")
      if iPos2 &gt; iPos1:
        DateTime = httpData[iPos1+1:iPos2]
        YYYY = int(DateTime[0:4])
        MM   = int(DateTime[5:7])
        DD   = int(DateTime[8:10])
        HH   = int(DateTime[11:13])
        MN   = int(DateTime[14:16])
        SS   = int(DateTime[17:19])
        # Set RTC using: Year,Month,Day,WeekDay,Hour,Min,Sec,MS
        rtc.datetime((YYYY,MM,DD,0,HH,MN,SS,0))
      else:
        DateTime = ''
      #end if
    except:
      DateTime = ''
  else:
    #lblWiFi.setText('WiFi not connected')
    DateTime = ''
  #end if
  return DateTime
#------------------------------------------------------------------

RightNow = rtc.datetime()
CurrentYear   = int(newDateTime[RTC_YYYY])
CurrentMonth  = int(newDateTime[RTC_MM])
CurrentDay    = int(newDateTime[RTC_DD])
CurrentHour   = int(newDateTime[RTC_HH])
CurrentMinute = int(newDateTime[RTC_MN])
CurrentSecond = int(newDateTime[RTC_SS])

</code></pre>
<p dir="auto">So, once the RTC is set, it will keep pretty accurate time until the M5Stack gets reset or powered off. Or you can just call the routine every day to resync it. Note that the PHP code is currently set for Canadian Pacific Time.<br />
Also note that the above URL is my personal webserver - you can use it for quick testing, but not long term please.</p>
]]></description><link>https://community.m5stack.com/post/7391</link><guid isPermaLink="true">https://community.m5stack.com/post/7391</guid><dc:creator><![CDATA[raystdenis]]></dc:creator><pubDate>Fri, 14 Feb 2020 05:23:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to make RTC clock with NTP on Wed, 22 Jan 2020 02:31:50 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/user/lilianz" aria-label="Profile: lilianz">@<bdi>lilianz</bdi></a> I regret to inform you that ntp_sync hasn't been present in the RTC module since firmware v1.2.3 I'm not entirely sure why, but thats the way it is. Perhaps you will find some clues on controlling the RTC from one of the many watch projects on our hackster page <a href="https://www.hackster.io/m5stack/projects" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.hackster.io/m5stack/projects</a></p>
]]></description><link>https://community.m5stack.com/post/7151</link><guid isPermaLink="true">https://community.m5stack.com/post/7151</guid><dc:creator><![CDATA[lukasmaximus]]></dc:creator><pubDate>Wed, 22 Jan 2020 02:31:50 GMT</pubDate></item></channel></rss>