Soohwan Kim / Mbed 2 deprecated UdpNtpClient

Dependencies:   NTPClient WIZnetInterface mbed

Fork of NTPClient_HelloWorld by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "NTPClient.h"
00004 
00005 EthernetInterface eth;
00006 NTPClient ntp;
00007 
00008 int main() 
00009 {
00010     uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};
00011     
00012     //eth.init(); //Use DHCP
00013     eth.init(mac_addr); //Use DHCP
00014 
00015     eth.connect();
00016    
00017     printf("Trying to update time...\r\n");
00018     //if (ntp.setTime("0.pool.ntp.org") == 0)
00019     if (ntp.setTime("jp.pool.ntp.org") == 0)
00020     {
00021       printf("Set time successfully\r\n");
00022       time_t ctTime;
00023       ctTime = time(NULL);
00024       printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
00025     }
00026     else
00027     {
00028       printf("Error\r\n");
00029     } 
00030    
00031     eth.disconnect();  
00032 
00033     while(1) {
00034     }
00035 }