RTC set with the http client.

Dependencies:   mbed lwip

Revision:
0:d868e62f9a3b
--- /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);
+    }
+}
+