UDP NTP Client
NTP
*Network Time Protocol - wikipedia
*참조:https://blog.cloudflare.com/understanding-and-mitigating-ntp-based-ddos-attacks/
Do UdpNtpClient
Import Program NTPClinet_HelloWorld: “http://developer.mbed.org/users/embeddist/code/UdpNtpClient/
if same program is existed, Import Name of NTPClinet_HelloWorld will be changed(2).
Remove mbed-rtos and EthernetInterface
Import WIZnetInterface”https://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/"(1)
Make Codes: porting to WIZnetInterface from EthernetInterface
UDP APIs in WIZnetInterface
Confirm packets by WireShark
Code Repository
I will update…
Ref. Code
#include "mbed.h"
#include "EthernetInterface.h"
#include "NTPClient.h"
EthernetInterface eth;
NTPClient ntp;
int main()
{
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};
//eth.init(); //Use DHCP
eth.init(mac_addr); //Use DHCP
eth.connect();
printf("Trying to update time...\r\n");
//if (ntp.setTime("0.pool.ntp.org") == 0)
if (ntp.setTime("jp.pool.ntp.org") == 0)
{
printf("Set time successfully\r\n");
time_t ctTime;
ctTime = time(NULL);
printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
}
else
{
printf("Error\r\n");
}
eth.disconnect();
while(1) {
}
}
댓글 없음:
댓글 쓰기