Dependencies: EthernetNetIf NTPClient_NetServices mbed
NTPClientExample.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "NTPClient.h" 00004 00005 EthernetNetIf eth; 00006 NTPClient ntp; 00007 00008 int main() { 00009 00010 printf("Start\n"); 00011 00012 printf("Setting up...\n"); 00013 EthernetErr ethErr = eth.setup(); 00014 if(ethErr) 00015 { 00016 printf("Error %d in setup.\n", ethErr); 00017 return -1; 00018 } 00019 printf("Setup OK\r\n"); 00020 00021 time_t ctTime; 00022 ctTime = time(NULL); 00023 printf("Current time is (UTC): %s\n", ctime(&ctTime)); 00024 00025 Host server(IpAddr(), 123, "0.uk.pool.ntp.org"); 00026 ntp.setTime(server); 00027 00028 ctTime = time(NULL); 00029 printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); 00030 00031 while(1) 00032 { 00033 00034 } 00035 00036 return 0; 00037 00038 }
Generated on Thu Jul 14 2022 17:08:28 by 1.7.2