NTPクラインアントの例

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
yueee_yt
Date:
Mon Dec 26 04:42:55 2011 +0000
Commit message:

Changed in this revision

EthernetNetIf.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
TextLCD.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 813e195356e1 EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Mon Dec 26 04:42:55 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yueee_yt/libraries/EthernetNetIf/m2t1yv
\ No newline at end of file
diff -r 000000000000 -r 813e195356e1 NTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Mon Dec 26 04:42:55 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yueee_yt/libraries/NTPClient/m2rm3g
\ No newline at end of file
diff -r 000000000000 -r 813e195356e1 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Dec 26 04:42:55 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 813e195356e1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 26 04:42:55 2011 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "NTPClient.h"
+#include "TextLCD.h"
+
+EthernetNetIf ethif; //for DHCP
+//EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx)); //for Static IP Address
+
+NTPClient ntp;
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+
+int main() {
+    char buffer[17];
+    lcd.locate(0,1);
+    lcd.printf("Start\n");
+    lcd.locate(0,1);
+    lcd.printf("Setting up...\n");
+    EthernetErr ethErr = ethif.setup();
+    if (ethErr) {
+        lcd.locate(0,1);
+        lcd.printf("Error %d in setup.\n", ethErr);
+        return -1;
+    }
+    lcd.locate(0,1);
+    lcd.printf("Setup OK\r\n");
+    IpAddr ethIp=ethif.getIp();
+    lcd.locate(0,1);
+    lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
+    wait(1.0f);
+
+    time_t ctTime;
+
+    Host server(IpAddr(), 123, "ntp2.jst.mfeed.ad.jp"); //near ntp server
+    ntp.setTime(server);
+//UTC-->JST +9Hour(32400Sec)
+    ctTime = time(NULL);
+    ctTime+=32400;
+    set_time(ctTime);
+
+    lcd.cls();
+    while (1) {
+        lcd.locate(0,0);
+        ctTime = time(NULL);
+        lcd.locate(0,0);
+        strftime(buffer,17,"%Y/%m/%d(%a)",localtime(&ctTime));
+        lcd.printf("%s",buffer);
+        lcd.locate(0,1);
+        strftime(buffer,17,"%X",localtime(&ctTime));
+        lcd.printf("%s",buffer);
+        wait(1.0f);
+    }
+    return 0;
+}
+
diff -r 000000000000 -r 813e195356e1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 26 04:42:55 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/078e4b97a13e