The program uses RPC over http to open a garage door over the internet. On a htm page is a link that calls a RPC function

Dependencies:   EthernetNetIf NTPClient_NetServices mbed HTTPServer

Files at this revision

API Documentation at this revision

Comitter:
jrsikken
Date:
Sat Jun 11 21:46:32 2011 +0000
Parent:
0:8c69f4c2bb0e
Child:
2:fb8f5c072e24
Commit message:

Changed in this revision

myGarageDoorOpenerHTTPServerExample.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/myGarageDoorOpenerHTTPServerExample.cpp	Fri Jun 10 21:20:19 2011 +0000
+++ b/myGarageDoorOpenerHTTPServerExample.cpp	Sat Jun 11 21:46:32 2011 +0000
@@ -2,6 +2,7 @@
 #include "EthernetNetIf.h"
 #include "HTTPServer.h"
 #include "RPCFunction.h"
+#include "NTPClient.h"
 
 DigitalOut led1(LED1, "led1");
 DigitalOut led2(LED2, "led2");
@@ -10,6 +11,7 @@
 DigitalOut rfout(p22,"rfout");
 
 LocalFileSystem fs("webfs");// Create the local filesystem under the name "local"
+LocalFileSystem local("local");
 
 EthernetNetIf eth(
     IpAddr(192,168,1,100), //IP Address
@@ -18,6 +20,8 @@
     IpAddr(192,168,1,254)  //DNS
 );
 HTTPServer svr;
+NTPClient ntp;
+    time_t ctTime;
 
 void sendbit(char a);
 void open(char * input, char * output);//Open garage door
@@ -44,7 +48,7 @@
     }
     printf("Setup OK\n");
 
-    FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
+    //FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
     FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
 
     svr.addHandler<SimpleHandler>("/hello");
@@ -55,6 +59,15 @@
     svr.bind(80);
     printf("Listening...\n");
 
+
+    Host server(IpAddr(), 123, "0.uk.pool.ntp.org");
+    ntp.setTime(server);
+    ctTime = time(NULL);
+    printf("Internet time is (UTC): %s\n", ctime(&ctTime));
+    FILE *fp = fopen("/local/test.txt", "a");
+    fprintf(fp,"Mbed restart (UTC): %s \r\n", ctime(&ctTime));
+    fclose(fp);
+
     Timer tm;
     tm.start();
     while (true) {
@@ -89,23 +102,29 @@
     }
 }
 
-    void open(char * input, char * output) {
-        led4=1;
-        for (char i = 0; i<20; i++) {
-            sendbit(1);//address A1
-            sendbit(0);//address A2
-            sendbit(0);//address A3
-            sendbit(0);//address A4
-            sendbit(1);//address A5
-            sendbit(0);//address A6 /data D6
-            sendbit(1);//address A7 /data D7
-            sendbit(0);//address A8 /data D8
-            sendbit(1);//address A9 /data D9
-            wait_ms(14);
-        }
-        led4=0;
-        sprintf(output, "<html><head><meta http-equiv=refresh content='5; url=../../index.htm'></head><body BGCOLOR=#A1F9FF>Opening,wait...</body></html>");
+void open(char * input, char * output) {
+    led4=1;
+    for (char i = 0; i<20; i++) {
+        sendbit(1);//address A1
+        sendbit(0);//address A2
+        sendbit(0);//address A3
+        sendbit(0);//address A4
+        sendbit(1);//address A5
+        sendbit(0);//address A6 /data D6
+        sendbit(1);//address A7 /data D7
+        sendbit(0);//address A8 /data D8
+        sendbit(1);//address A9 /data D9
+        wait_ms(14);
     }
+    led4=0;
+
+    FILE *fp = fopen("/local/test.txt", "a");
+    ctTime = time(NULL);
+    fprintf(fp,"Open sesame (UTC): %s \n", ctime(&ctTime));
+    fclose(fp);
+
+    sprintf(output, "<html><head><meta http-equiv=refresh content='5; url=../../index.htm'></head><body BGCOLOR=#A1F9FF>Opening,wait...</body></html>");
+}