LCD clock display set using NTP server

Dependencies:   EthernetNetIf NTPClient_NetServices TextLCD mbed

Fork of Internet_LCD_Clock by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Thu Apr 12 01:44:02 2012 +0000
Child:
1:09fcc9b81f23
Commit message:

Changed in this revision

EthernetNetIf.lib Show annotated file 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 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Apr 12 01:44:02 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Internet_LCD_Clock.cpp	Thu Apr 12 01:44:02 2012 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "NTPClient.h"
+#include "TextLCD.h"
+// 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;
+NTPClient ntp;
+
+int main() {
+//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
+        printf("Error %d in setup.\n\r", ethErr);
+        lcd.cls();
+        lcd.printf("Network Error \n\r %d",ethErr);
+        return -1;
+    }
+    lcd.cls();
+    ctTime = time(NULL);
+    lcd.printf("Reading Time...\n\r");
+    //specify time server URL
+    Host server(IpAddr(), 123, "0.uk.pool.ntp.org");
+    //Read time from server
+    ntp.setTime(server);
+    ctTime = time(NULL);
+    lcd.printf("Time set");
+    //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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Thu Apr 12 01:44:02 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Apr 12 01:44:02 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 12 01:44:02 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da