get internet time on k64f

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Fork of Internet_LCD_Clock by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
jerryzj
Date:
Fri Apr 07 14:11:00 2017 +0000
Parent:
1:09fcc9b81f23
Commit message:
get internet time

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show diff for this revision Revisions of this file
Internet_LCD_Clock.cpp 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
TextLCD.lib 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 09fcc9b81f23 -r ec0b6a5ccef7 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Apr 07 14:11:00 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jerryzj/code/EthernetInterface/#80ba6a6a1c57
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 EthernetNetIf.lib
--- a/EthernetNetIf.lib	Sat Apr 14 01:12:23 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 Internet_LCD_Clock.cpp
--- a/Internet_LCD_Clock.cpp	Sat Apr 14 01:12:23 2012 +0000
+++ b/Internet_LCD_Clock.cpp	Fri Apr 07 14:11:00 2017 +0000
@@ -1,41 +1,36 @@
 #include "mbed.h"
-#include "EthernetNetIf.h"
+#include "EthernetInterface.h"
 #include "NTPClient.h"
-#include "TextLCD.h"
+
+DigitalIn  Switch(SW2);
 // Internet of Things clock example: LCD time is set via internet NTP time server
-TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3
-EthernetNetIf eth;
+EthernetInterface eth;
 NTPClient ntp;
 
 int main() {
-//system time structure
+    //system time structure
     time_t ctTime;
-    //clear LCD
-    lcd.cls();
+    
     // lcd.printf prints to LCD display;
-    lcd.printf("Get IP addr...");
-    EthernetErr ethErr = eth.setup();
-    //Get an Internet IP address using DHCP
-    if (ethErr) {
-        //error or timeout getting an IP address
-        lcd.cls();
-        lcd.printf("Network Error \n\r %d",ethErr);
-        return -1;
-    }
-    lcd.cls();
-    lcd.printf("Reading Time...\n\r");
+    printf("Get IP addr...\r\n");
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address-a is %s\r\n", eth.getIPAddress());
+    printf("Reading Time...\r\n");
     //specify time server URL
-    Host server(IpAddr(), 123, "0.uk.pool.ntp.org");
+    TCPSocketConnection sock;
+    sock.connect("tock.stdtime.gov.tw", 123);
     //Read time from server
-    ntp.setTime(server);
-    lcd.printf("Time set");
+    ntp.setTime("tock.stdtime.gov.tw");
+    printf("Time set\n");
     //Delay for human time to read LCD display
     wait(1);
     while (1) {
-        // loop and periodically update the LCD's time display
-        lcd.cls();
-        ctTime = time(NULL);
-        lcd.printf("UTC:  %s", ctime(&ctTime));
-        wait(.25);
+        if(Switch==0){
+            // loop and periodically update the LCD's time display
+            ctTime = time(NULL);
+            printf("UTC:  %s\r\n", ctime(&ctTime));
+            wait(.25);
+        }
     }
 }
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 NTPClient.lib
--- a/NTPClient.lib	Sat Apr 14 01:12:23 2012 +0000
+++ b/NTPClient.lib	Fri Apr 07 14:11:00 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
+http://mbed.org/users/donatien/code/NTPClient/#881559865a93
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 TextLCD.lib
--- a/TextLCD.lib	Sat Apr 14 01:12:23 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Apr 07 14:11:00 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 09fcc9b81f23 -r ec0b6a5ccef7 mbed.bld
--- a/mbed.bld	Sat Apr 14 01:12:23 2012 +0000
+++ b/mbed.bld	Fri Apr 07 14:11:00 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
+https://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file