RTC set with the http client.

Dependencies:   mbed lwip

Files at this revision

API Documentation at this revision

Comitter:
nucho
Date:
Sat Jun 05 16:42:53 2010 +0000
Commit message:

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
RTCsetwithHttpClient.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 d868e62f9a3b HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Sat Jun 05 16:42:53 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_unsupported/code/lwip/
\ No newline at end of file
diff -r 000000000000 -r d868e62f9a3b RTCsetwithHttpClient.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTCsetwithHttpClient.cpp	Sat Jun 05 16:42:53 2010 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include "HTTPClient.h"
+
+#define PAGE_SIZE 77
+
+HTTPClient http;
+
+int main(void) {
+    char result[PAGE_SIZE+1];
+    char buf[40];
+    char *e;
+
+    time_t seconds;
+
+    http.get("http://ntp-a1.nict.go.jp/cgi-bin/ntp", result,PAGE_SIZE);
+    result[PAGE_SIZE]='\0';
+
+    
+    int start_body=strstr(result,"<BODY>")-result+7;
+    int end_body = strstr(result,"</BODY>")-result-1;
+    strncpy(buf, result+start_body, end_body-start_body);
+    buf[end_body-start_body]='\0';
+    
+    seconds = strtoul(buf,&e,10)-2208988800UL;
+    seconds += 32400;//JST TIME
+    set_time(seconds);
+
+    // Work is done!
+    while (1) {
+        seconds = time(NULL);
+        strftime(buf,sizeof(buf),"%Y/%m/%d %a\n%H:%M:%S  Ready!", localtime(&seconds));
+        printf("%s\n", buf);
+         wait(1);
+    }
+}
+
diff -r 000000000000 -r d868e62f9a3b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jun 05 16:42:53 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/029aa53d7323