demo program for the TimeZone library (see http://mbed.org/users/hlipka/notebook/time-zone-handling ).

Dependencies:   NetServices mbed

Files at this revision

API Documentation at this revision

Comitter:
hlipka
Date:
Wed Dec 22 23:21:20 2010 +0000
Commit message:
initial version

Changed in this revision

NetServices.lib Show annotated file Show diff for this revision Revisions of this file
TimeZone.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 255c470c37ca NetServices.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetServices.lib	Wed Dec 22 23:21:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/segundo/code/NetServices/#4e2468d7d5cb
diff -r 000000000000 -r 255c470c37ca TimeZone.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TimeZone.lib	Wed Dec 22 23:21:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/TimeZone/#0c7207d674d3
diff -r 000000000000 -r 255c470c37ca main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 22 23:21:20 2010 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+
+#include "EthernetNetIf.h"
+#include "NTPClient.h"
+
+#include "Time.h"
+
+LocalFileSystem local("local");
+
+void updateTime()
+{
+    time_t ctTime;
+    time(&ctTime);
+    printf("Current time is (UTC): %s\n", ctime(&ctTime));
+
+    NTPClient ntp;
+    Host server(IpAddr(), 123, "0.de.pool.ntp.org");
+    ntp.setTime(server);
+
+  printf("set time ok\n");
+  time(&ctTime);
+  printf("Current time is (UTC): %s\n", ctime(&ctTime));
+    
+}
+
+int main() {
+    void* p1=malloc(16000); // to ensure we have enough heap after NTP setup
+
+    printf("setup\n");
+    EthernetNetIf eth;
+    EthernetErr ethErr;
+    printf("Setting up...\n");
+    do {
+        ethErr = eth.setup();
+        if (ethErr) printf("waiting for network...\n", ethErr);
+    } while (ethErr != ETH_OK);
+
+    printf("setup ok\n");
+
+    updateTime();
+    
+    free(p1); // reclaim back memory
+
+    char *buf=new char[32];
+
+    Time *time=new Time();
+    TimeStamp *timestamp=time->getTime();
+
+    snprintf(buf,32,"%.2d/%.2d %.2d:%.2d:%.2d",
+        timestamp->getMonth()+1, timestamp->getDay(), 
+        timestamp->getHour(), timestamp->getMinute(), timestamp->getSecond());
+    printf("time=%s\n",buf);
+
+    delete [] buf;
+    delete timestamp;
+    delete time;
+
+}
diff -r 000000000000 -r 255c470c37ca mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 22 23:21:20 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e