Tests Ethernet connection and ability to access a public NTP server.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
markrad
Date:
Tue May 30 21:41:24 2017 +0000
Commit message:
Basic NTP test

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
NTPClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 433bf5e7bce1 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue May 30 21:41:24 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/EthernetInterface/#4d7bff17a592
diff -r 000000000000 -r 433bf5e7bce1 NTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Tue May 30 21:41:24 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/loopsva/code/NTPClient/#2c0aaa9a3e87
diff -r 000000000000 -r 433bf5e7bce1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 30 21:41:24 2017 +0000
@@ -0,0 +1,61 @@
+#include <stdio.h>
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "NTPClient.h"
+
+DigitalOut led1(LED1);
+
+void loopForever()
+{
+    printf("Halt\r\n");
+
+    while (true) {
+        printf(".");
+        led1 = !led1;
+        Thread::wait(1000);
+    }
+}
+
+int main()
+{
+    led1 = false;
+    int result = 0;
+    
+    printf("\r\nBegin NTP test\r\n");
+    
+    result = EthernetInterface::init();
+    
+    if (result != 0)
+    {
+        printf("Init failed - %d\r\n", result);
+        loopForever();
+    }
+    
+    result = EthernetInterface::connect();
+    
+    if (result != 0)
+    {
+        printf("Connect failed - %d\r\n", result);
+        loopForever();
+    }
+    
+    time_t ctTime;
+    ctTime = time(NULL);  
+  
+    printf("Current time is (UTC): %s\r\n", ctime(&ctTime));      
+    
+    NTPClient ntp;
+    
+    result = ntp.setTime("0.pool.ntp.org");
+    
+    if (result != 0)
+    {
+        printf("Settime failed - %d\r\n", result);
+        loopForever();
+    }
+    
+    ctTime = time(NULL);  
+    printf("\r\nTime is now (UTC): %s\r\n", ctime(&ctTime)); 
+    loopForever();
+}
\ No newline at end of file
diff -r 000000000000 -r 433bf5e7bce1 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue May 30 21:41:24 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#5a85840ab54e
diff -r 000000000000 -r 433bf5e7bce1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 30 21:41:24 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3
\ No newline at end of file