<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
		<id>http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4%2Fzh</id>
		<title>Microduino W5500网络（十二）————用NTP获取Internet时间/zh - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4%2Fzh"/>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh&amp;action=history"/>
		<updated>2026-04-21T08:22:32Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https//wiki.microduino.cn/index.php?title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh&amp;diff=7684&amp;oldid=prev</id>
		<title>Radiumray9@gmail.com：/* 程序 */</title>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh&amp;diff=7684&amp;oldid=prev"/>
				<updated>2015-02-02T03:24:49Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;程序&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;zh-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;2015年2月2日 (一) 03:24的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l39&quot; &gt;第39行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第39行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==程序==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==程序==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Advanced_Tutorial/W5500Code/MicroduinoW5500Twelven MicroduinoW5500Twelven]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==调试==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==调试==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Radiumray9@gmail.com</name></author>	</entry>

	<entry>
		<id>https//wiki.microduino.cn/index.php?title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh&amp;diff=7656&amp;oldid=prev</id>
		<title>Radiumray9@gmail.com：Created page with &quot;{| style=&quot;width: 800px;&quot; |- | ==目的== 本教程将教大家如何通过NTP（网络时间协议）从互联网得到一个准确的时间。  ==设备== *'''Microduino-Co...&quot;</title>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Microduino_W5500%E7%BD%91%E7%BB%9C%EF%BC%88%E5%8D%81%E4%BA%8C%EF%BC%89%E2%80%94%E2%80%94%E2%80%94%E2%80%94%E7%94%A8NTP%E8%8E%B7%E5%8F%96Internet%E6%97%B6%E9%97%B4/zh&amp;diff=7656&amp;oldid=prev"/>
				<updated>2015-02-01T05:04:59Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{| style=&amp;quot;width: 800px;&amp;quot; |- | ==目的== 本教程将教大家如何通过NTP（网络时间协议）从互联网得到一个准确的时间。  ==设备== *&amp;#039;&amp;#039;&amp;#039;Microduino-Co...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| style=&amp;quot;width: 800px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
==目的==&lt;br /&gt;
本教程将教大家如何通过NTP（网络时间协议）从互联网得到一个准确的时间。&lt;br /&gt;
&lt;br /&gt;
==设备==&lt;br /&gt;
*'''[[Microduino-Core/zh]]'''&lt;br /&gt;
*'''[[Microduino-USBTTL/zh]]'''&lt;br /&gt;
*'''[[Microduino-W5500/zh]]'''&lt;br /&gt;
*'''[[Microduino-RJ45/zh]]'''&lt;br /&gt;
&lt;br /&gt;
*其他硬件设备&lt;br /&gt;
**USB数据连接线   一根&lt;br /&gt;
&lt;br /&gt;
==NTP==&lt;br /&gt;
&lt;br /&gt;
NTP是一个客户端-服务器协议，他工作在应用层，采用UDP传输协议，使用端口为123。&lt;br /&gt;
&lt;br /&gt;
如果你发送一个请求到某个时间服务器，时间服务器会返回一个64位的值（时间戳）：&lt;br /&gt;
&lt;br /&gt;
*前32位表示自1900年1月1日间隔的秒数；&lt;br /&gt;
*后32位用以表示秒以下的部份，并加上网络延时量的估计.理论上可以精确到到2的-32次方秒，实际使用大约只有50ms（广域网）左右，在局域网可达1ms。在实际中您应找最近而且最稳定的时间服务器作为时间源。&lt;br /&gt;
[[File:NTP.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==原理图==&lt;br /&gt;
&lt;br /&gt;
*Microduino-W5500&lt;br /&gt;
*Microduino-RJ45&lt;br /&gt;
*Microduino-Core&lt;br /&gt;
*Microduino-USBTTL&lt;br /&gt;
层层堆叠，再插上网线。&lt;br /&gt;
&lt;br /&gt;
如下图所示：&lt;br /&gt;
&lt;br /&gt;
[[File:MicroduinoW5500Show.png|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
==程序==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==调试==&lt;br /&gt;
&lt;br /&gt;
步骤一：首先需要确保你的IDE中有_02_Microduino_Ethernet_WIZ库，如果没有下载放到你的IDE的libraries文件夹中，重启IDE。&lt;br /&gt;
&lt;br /&gt;
步骤二：如果你的IDE的libraries文件夹中还有之前的Ethernet库的话，需要删除掉，因为之前的Ethernet是根据W5100协议编写的。&lt;br /&gt;
&lt;br /&gt;
然后需要改动一下_02_Microduino_Ethernet_WIZ文件以使库函数与Microduino-W5500模块的引脚对应：&lt;br /&gt;
&lt;br /&gt;
先找到_02_Microduino_Ethernet_WIZ库中的utility文件夹里的w5100.h&lt;br /&gt;
&lt;br /&gt;
把代码中的 #define wiz_cs_pin 8	//CS_PIN 改为 #define wiz_cs_pin 10	//CS_PIN  就可以了。&lt;br /&gt;
&lt;br /&gt;
步骤三：解释一下代码：&lt;br /&gt;
&lt;br /&gt;
在互联网上有很多时间服务器：比如美国的 NIST (National Institute of Standards and Technology) 提供整个互联网的时间服务；&lt;br /&gt;
&lt;br /&gt;
这里我们使用：IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server&lt;br /&gt;
&lt;br /&gt;
首先发送NTP包到timeserver:&lt;br /&gt;
&lt;br /&gt;
sendNTPpacket(timeServer); // send an NTP packet to a time server&lt;br /&gt;
&lt;br /&gt;
然后，如果从tiemServer接收到数据包之后就解析数据包：&lt;br /&gt;
&lt;br /&gt;
  if ( Udp.parsePacket() ) {  &lt;br /&gt;
    // We've received a packet, read the data from it&lt;br /&gt;
    Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer&lt;br /&gt;
&lt;br /&gt;
    //the timestamp starts at byte 40 of the received packet and is four bytes,&lt;br /&gt;
    // or two words, long. First, esxtract the two words:&lt;br /&gt;
&lt;br /&gt;
    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);&lt;br /&gt;
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);  &lt;br /&gt;
    // combine the four bytes (two words) into a long integer&lt;br /&gt;
    // this is NTP time (seconds since Jan 1 1900):&lt;br /&gt;
    unsigned long secsSince1900 = highWord &amp;lt;&amp;lt; 16 | lowWord;  &lt;br /&gt;
    Serial.print(&amp;quot;Seconds since Jan 1 1900 = &amp;quot; );&lt;br /&gt;
    Serial.println(secsSince1900);               &lt;br /&gt;
&lt;br /&gt;
    // now convert NTP time into everyday time:&lt;br /&gt;
    Serial.print(&amp;quot;Unix time = &amp;quot;);&lt;br /&gt;
    // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:&lt;br /&gt;
    const unsigned long seventyYears = 2208988800UL;     &lt;br /&gt;
    // subtract seventy years:&lt;br /&gt;
    unsigned long epoch = secsSince1900 - seventyYears;  &lt;br /&gt;
    // print Unix time:&lt;br /&gt;
    Serial.println(epoch);                               &lt;br /&gt;
&lt;br /&gt;
    // print the hour, minute and second:&lt;br /&gt;
    Serial.print(&amp;quot;The UTC time is &amp;quot;);       // UTC is the time at Greenwich Meridian (GMT)&lt;br /&gt;
    Serial.print((epoch  % 86400L) / 3600); // print the hour (86400 equals secs per day)&lt;br /&gt;
    Serial.print(':');  &lt;br /&gt;
    if ( ((epoch % 3600) / 60) &amp;lt; 10 ) {&lt;br /&gt;
      // In the first 10 minutes of each hour, we'll want a leading '0'&lt;br /&gt;
      Serial.print('0');&lt;br /&gt;
    }&lt;br /&gt;
    Serial.print((epoch  % 3600) / 60); // print the minute (3600 equals secs per minute)&lt;br /&gt;
    Serial.print(':'); &lt;br /&gt;
    if ( (epoch % 60) &amp;lt; 10 ) {&lt;br /&gt;
      // In the first 10 seconds of each minute, we'll want a leading '0'&lt;br /&gt;
      Serial.print('0');&lt;br /&gt;
    }&lt;br /&gt;
    Serial.println(epoch %60); // print the second&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
步骤四：下载代码并编译通过。&lt;br /&gt;
&lt;br /&gt;
步骤五：打开串口看看是否显示了时间。&lt;br /&gt;
&lt;br /&gt;
==结果==&lt;br /&gt;
&lt;br /&gt;
串口里显示了时间：&lt;br /&gt;
&lt;br /&gt;
[[File:MicroduinoW5500NTPShowTime.png|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
==扩展==&lt;br /&gt;
为了看时间更加方便美观，你可以使用Microduino OLED来显示时间：&lt;br /&gt;
[[File:MicroduinoW5500TimeShow1.png|600px|center|thumb]]&lt;br /&gt;
[[File:MicroduinoW5500TimeShow2.png|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
==视频==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Radiumray9@gmail.com</name></author>	</entry>

	</feed>