Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NTPClient WIZnetInterface mbed
Fork of NTPClient_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 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 }
Generated on Wed Jul 20 2022 04:05:15 by
1.7.2
