Simple example demonstrating how to use the NTP Client to set the time
Dependencies: NTPClient mbed mbed-rtos EthernetInterface
Fork of HTTPClient_HelloWorld by
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 eth.init(); //Use DHCP 00011 00012 eth.connect(); 00013 00014 printf("Trying to update time...\r\n"); 00015 if (ntp.setTime("0.pool.ntp.org") == 0) 00016 { 00017 printf("Set time successfully\r\n"); 00018 time_t ctTime; 00019 ctTime = time(NULL); 00020 printf("Time is set to (UTC): %s\r\n", ctime(&ctTime)); 00021 } 00022 else 00023 { 00024 printf("Error\r\n"); 00025 } 00026 00027 eth.disconnect(); 00028 00029 while(1) { 00030 } 00031 }
Generated on Wed Jul 13 2022 01:16:14 by 1.7.2