internet clock via ethernet cable

Dependencies:   4DGL-uLCD-SE EthernetInterface NTPClient mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
wye11
Date:
Sat Jan 30 07:33:17 2016 +0000
Commit message:
internet clock via ethernet;

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
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 80d83068b7bd 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sparkfun/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r 80d83068b7bd EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sparkfun/code/EthernetInterface/#2fc406e2553f
diff -r 000000000000 -r 80d83068b7bd NTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sparkfun/code/NTPClient/#881559865a93
diff -r 000000000000 -r 80d83068b7bd main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,63 @@
+// Internet Clock with LCD based on the work by Jim Hamblen and Tyler Lisowski
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "NTPClient.h"
+#include "uLCD_4DGL.h"
+
+// Parameters
+char* domain_name = "0.uk.pool.ntp.org";
+int port_number = 123;
+
+// Networking
+EthernetInterface eth;
+NTPClient ntp_client;
+
+// Graphic LCD - TX, RX, and RES pins
+uLCD_4DGL uLCD(p9,p10,p11);
+
+int main() {
+
+    time_t ct_time;
+    char time_buffer[80];    
+
+    // Initialize LCD
+    uLCD.baudrate(115200);
+    uLCD.background_color(BLACK);
+    uLCD.cls();
+
+    // Connect to network and wait for DHCP
+    uLCD.locate(0,0); 
+    uLCD.printf("Getting IP Address\n");
+    eth.init();
+    if ( eth.connect() == -1 ) {
+        uLCD.printf("ERROR: Could not\nget IP address");
+        return -1;
+    }
+    uLCD.printf("IP address is \n%s\n\n",eth.getIPAddress());
+    wait(1);
+
+    // Read time from server
+    uLCD.printf("Reading time...\n\r");
+    ntp_client.setTime(domain_name, port_number);
+    uLCD.printf("Time set\n");
+    wait(2);
+    eth.disconnect();
+
+    // Reset LCD
+    uLCD.background_color(WHITE);
+    uLCD.textbackground_color(WHITE);
+    uLCD.color(RED);
+    uLCD.cls();
+    uLCD.text_height(2);
+
+    // Loop and update clock
+    while (1) {
+        uLCD.locate(0, 1);
+        ct_time = time(NULL);
+        strftime(time_buffer, 80, "    %a %b %d\n    %T %p %z\n    %Z\n", \
+                                                localtime(&ct_time));
+        uLCD.printf("    UTC/GMT:\n%s", time_buffer);
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r 80d83068b7bd mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sparkfun/code/mbed-rtos/#bc9729798a19
diff -r 000000000000 -r 80d83068b7bd mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 30 07:33:17 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file