<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Arduino%3A_RTC_DS1302_NTP_Sync</id>
	<title>Arduino: RTC DS1302 NTP Sync - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Arduino%3A_RTC_DS1302_NTP_Sync"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;action=history"/>
	<updated>2026-04-19T21:56:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;diff=51207&amp;oldid=prev</id>
		<title>Onnowpurbo at 09:48, 30 May 2018</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;diff=51207&amp;oldid=prev"/>
		<updated>2018-05-30T09:48:58Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;amp;diff=51207&amp;amp;oldid=51206&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;diff=51206&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot;// time ntp RTC DS1302 set  #include &lt;Time.h&gt; #include &lt;SPI.h&gt; #include &lt;Ethernet.h&gt; #include &lt;EthernetUdp.h&gt; #include &lt;DS1302.h&gt;  // Init the DS1302 // DS1302 rtc([CE/RST], [...&quot;</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Arduino:_RTC_DS1302_NTP_Sync&amp;diff=51206&amp;oldid=prev"/>
		<updated>2018-05-30T09:47:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;// time ntp RTC DS1302 set  #include &amp;lt;Time.h&amp;gt; #include &amp;lt;SPI.h&amp;gt; #include &amp;lt;Ethernet.h&amp;gt; #include &amp;lt;EthernetUdp.h&amp;gt; #include &amp;lt;DS1302.h&amp;gt;  // Init the DS1302 // DS1302 rtc([CE/RST], [...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;// time ntp RTC DS1302 set&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Time.h&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#include &amp;lt;Ethernet.h&amp;gt;&lt;br /&gt;
#include &amp;lt;EthernetUdp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;DS1302.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Init the DS1302&lt;br /&gt;
// DS1302 rtc([CE/RST], [I/O], [CLOCK]);&lt;br /&gt;
DS1302 rtc(8, 7, 6);&lt;br /&gt;
&lt;br /&gt;
// Ethernet library configuration&lt;br /&gt;
byte mac[] = { 0x24, 0x7B, 0xA2, 0x4A, 0x52, 0x10 };&lt;br /&gt;
IPAddress timeServer(128, 138, 140, 44 ); // time.nist.gov&lt;br /&gt;
&lt;br /&gt;
unsigned int localPort = 8888;&lt;br /&gt;
const int NTP_PACKET_SIZE= 48;     &lt;br /&gt;
byte packetBuffer[NTP_PACKET_SIZE]; &lt;br /&gt;
EthernetUDP Udp;                   &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
  // Set the clock to run-mode, and disable the write protection&lt;br /&gt;
  rtc.halt(false);&lt;br /&gt;
  rtc.writeProtect(false);&lt;br /&gt;
&lt;br /&gt;
  // Setup Communication&lt;br /&gt;
  Serial.begin(9600);&lt;br /&gt;
  Ethernet.begin(mac);&lt;br /&gt;
  Udp.begin(localPort);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Serial.print(&amp;quot;get time&amp;quot;);&lt;br /&gt;
  setSyncInterval(10); // Set seconds between re-sync&lt;br /&gt;
  getNtpTime;&lt;br /&gt;
&lt;br /&gt;
  // The following lines can be commented out to use the values already stored in the DS1302&lt;br /&gt;
  rtc.setDOW(WEDNESDAY);        // Set Day-of-Week to MONDAY&lt;br /&gt;
  // rtc.setTime(13, 0, 0);     // Set the time to 12:00:00 (24hr format)&lt;br /&gt;
  rtc.setDate(30, 5, 2018);   // Set the date to Feb 2, 2016&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
  setSyncProvider(getNtpTime);&lt;br /&gt;
&lt;br /&gt;
  rtc.setTime(hour()+7, minute(), second());&lt;br /&gt;
&lt;br /&gt;
  // Send Day-of-Week&lt;br /&gt;
  Serial.print(rtc.getDOWStr());&lt;br /&gt;
  Serial.print(&amp;quot; &amp;quot;);&lt;br /&gt;
  &lt;br /&gt;
  // Send date&lt;br /&gt;
  Serial.print(rtc.getDateStr());&lt;br /&gt;
  Serial.print(&amp;quot; -- &amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
  // Send time&lt;br /&gt;
  Serial.println(rtc.getTimeStr());&lt;br /&gt;
  &lt;br /&gt;
  getNtpTime;&lt;br /&gt;
  // delay(1000);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
/*-------- NTP code ----------*/&lt;br /&gt;
&lt;br /&gt;
unsigned long getNtpTime()&lt;br /&gt;
{&lt;br /&gt;
  sendNTPpacket(timeServer); // send an NTP packet to a time server&lt;br /&gt;
    delay(500);&lt;br /&gt;
   &lt;br /&gt;
    if ( Udp.parsePacket() ) {&lt;br /&gt;
     Udp.read(packetBuffer,NTP_PACKET_SIZE);&lt;br /&gt;
     unsigned long hi = word(packetBuffer[40], packetBuffer[41]);&lt;br /&gt;
     unsigned long low = word(packetBuffer[42], packetBuffer[43]);&lt;br /&gt;
     unsigned long secsSince1900 = hi &amp;lt;&amp;lt; 16 | low; &lt;br /&gt;
     const unsigned long seventyYears = 2208988800UL;     &lt;br /&gt;
     unsigned long epoch = secsSince1900 - seventyYears;&lt;br /&gt;
     return epoch;&lt;br /&gt;
  }&lt;br /&gt;
  return 0; // return 0 if unable to get the time&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned long sendNTPpacket(IPAddress&amp;amp; address)&lt;br /&gt;
{&lt;br /&gt;
  memset(packetBuffer, 0, NTP_PACKET_SIZE);  // set all bytes in the buffer to 0&lt;br /&gt;
&lt;br /&gt;
  // Initialize values needed to form NTP request&lt;br /&gt;
  packetBuffer[0] = B11100011;   // LI, Version, Mode&lt;br /&gt;
  packetBuffer[1] = 0;     // Stratum&lt;br /&gt;
  packetBuffer[2] = 6;     // Max Interval between messages in seconds&lt;br /&gt;
  packetBuffer[3] = 0xEC;  // Clock Precision&lt;br /&gt;
  // bytes 4 - 11 are for Root Delay and Dispersion and were set to 0 by memset&lt;br /&gt;
  packetBuffer[12]  = 49;  // four-byte reference ID identifying&lt;br /&gt;
  packetBuffer[13]  = 0x4E;&lt;br /&gt;
  packetBuffer[14]  = 49;&lt;br /&gt;
  packetBuffer[15]  = 52;&lt;br /&gt;
&lt;br /&gt;
  // send the packet requesting a timestamp:&lt;br /&gt;
  Udp.beginPacket(address, 123); //NTP requests are to port 123&lt;br /&gt;
  Udp.write(packetBuffer,NTP_PACKET_SIZE);&lt;br /&gt;
  Udp.endPacket();&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>