HTTP Server, WebSocket support

Dependencies:   EthernetInterface HTTPD mbed-rtos mbed mbed-rpc

HTTP Server library
for EthernetInterface or compatible interface

multi connection, keep alive support.

Filesystem:

http://192.168.1.2/mbed.htm

CGI:

http://192.168.1.2/cgi-bin/test?query

WebSocket:

ws://192.168.1.2/ws/test

RPC:

http://192.168.1.2/rpc/DigitalOut/new%20LED4%20myled
http://192.168.1.2/rpc/myled/write%201

Import libraryHTTPD

HTTP Server, WebSocket support

HTTPD.h

#define HTTPD_PORT 80
#define HTTPD_MAX_CLIENTS 2
#define HTTPD_KEEPALIVE 10

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Wed Nov 13 06:59:58 2013 +0000
Parent:
0:c4a353ed707d
Commit message:
RPC support

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rpc.lib Show annotated file Show diff for this revision Revisions of this file
diff -r c4a353ed707d -r 2971dd3e5168 main.cpp
--- a/main.cpp	Wed Nov 13 02:00:05 2013 +0000
+++ b/main.cpp	Wed Nov 13 06:59:58 2013 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "rtos.h"
 #include "EthernetInterface.h"
+#include "mbed_rpc.h"
 #include "HTTPD.h"
 
 EthernetInterface *eth;
@@ -41,20 +42,39 @@
     httpd->sendWebsocket(id, buf, i);
 }
 
+void callback_rpc (int id) {
+    char buf[40], outbuf[40];
+
+    strcpy(buf, "/");
+    httpd->urldecode(httpd->getFilename(id), &buf[1], sizeof(buf) - 2);
+    RPC::call(buf, outbuf);
+
+    printf("RPC id %d '%s' '%s'\r\n", id, buf, outbuf);
+    httpd->send(id, outbuf, strlen(outbuf), "Content-Type: text/plain\r\n");
+}
+
 int main () {
 
     pc.baud(115200);
     printf("HTTP Server...\r\n");
 
     eth = new EthernetInterface;
-    eth->init(); //Use DHCP
-//    eth->init("192.168.1.2", "255.255.255.0", "192.168.1.1");
+//    eth->init(); //Use DHCP
+    eth->init("192.168.1.2", "255.255.255.0", "192.168.1.1");
     if (eth->connect()) return -1;
     printf("IP Address is %s\r\n", eth->getIPAddress());
 
+//    RPC::add_rpc_class<RpcAnalogIn>();
+//    RPC::add_rpc_class<RpcAnalogOut>();
+    RPC::add_rpc_class<RpcDigitalIn>();
+    RPC::add_rpc_class<RpcDigitalOut>();
+    RPC::add_rpc_class<RpcDigitalInOut>();
+    RPC::add_rpc_class<RpcPwmOut>();
+
     httpd = new HTTPD;
     httpd->attach("/cgi-bin/", &callback_cgi);
     httpd->attach("/ws/", &callback_ws);
+    httpd->attach("/rpc/", &callback_rpc);
     httpd->attach("/", "/local/");
     httpd->start(80);
     printf("httpd ready\r\n");
diff -r c4a353ed707d -r 2971dd3e5168 mbed-rpc.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rpc.lib	Wed Nov 13 06:59:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rpc/#4490a0d9cb2a