dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "test_env.h"
00003 #include "EthernetInterface.h"
00004 #include "NTPClient.h"
00005 
00006 int main() {
00007     MBED_HOSTTEST_TIMEOUT(15);
00008     MBED_HOSTTEST_SELECT(default_auto);
00009     MBED_HOSTTEST_DESCRIPTION(NTP client);
00010     MBED_HOSTTEST_START("NET_8");
00011 
00012     EthernetInterface eth;
00013     NTPClient ntp;
00014     eth.init(); //Use DHCP
00015     eth.connect();
00016 
00017     // NTP set time
00018     {
00019         bool result = true;
00020         const char *url_ntp_server = "0.pool.ntp.org";
00021         printf("NTP_SETTIME: Trying to update time... \r\n");
00022         const int ret = ntp.setTime(url_ntp_server);
00023         if (ret == 0) {
00024           time_t ctTime = time(NULL);
00025           printf("NTP_SETTIME: UTC Time read successfully ... [OK]\r\n");
00026           printf("NTP_SETTIME: %s\r\n", ctime(&ctTime));
00027         }
00028         else {
00029           printf("NTP_SETTIME: Error(%d) ... [FAIL]\r\n", ret);
00030           result = false;
00031         }
00032 
00033         if (result == false) {
00034             MBED_HOSTTEST_RESULT(false);
00035         }
00036     }
00037     eth.disconnect();
00038     MBED_HOSTTEST_RESULT(true);
00039 }