Chronos . / Mbed OS NTPClient_example

Dependencies:   NTPClient

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "NTPClient.h"
00003 #include "EthernetInterface.h"
00004   
00005 int main() {
00006 
00007   EthernetInterface eth;
00008 
00009   printf("Setting up...\n");
00010   
00011   int ethError = eth.connect();
00012     
00013   if(ethError == 0)
00014   {
00015     NTPClient ntp(eth);
00016     printf("ETH is up : %s\n", eth.get_ip_address());
00017     time_t ctTime;
00018     ctTime = time(NULL);  
00019     printf("Current time is (UTC): %s\n", ctime(&ctTime));  
00020 
00021     ntp.setTime("0.uk.pool.ntp.org");
00022     
00023     ctTime = time(NULL);  
00024     printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); 
00025   
00026     eth.disconnect();
00027   } else {
00028       printf("Connect failed (%d)", ethError);
00029   }
00030   
00031   return 0;
00032   
00033 }