HTTP and WebSocket Server with RTOS for GSwifiInterface library Please see: https://mbed.org/users/gsfan/notebook/gswifiinterface_httpd/

Dependencies:   GSwifiInterface SDFileSystem mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Thu Jun 05 04:25:13 2014 +0000
Commit message:
1st build

Changed in this revision

GSwifiInterface.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.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-rtos.lib 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 eb3c6b3965fa GSwifiInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GSwifiInterface.lib	Thu Jun 05 04:25:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/gsfan/code/GSwifiInterface/#d035412a7803
diff -r 000000000000 -r eb3c6b3965fa SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Jun 05 04:25:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r 000000000000 -r eb3c6b3965fa main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 05 04:25:13 2014 +0000
@@ -0,0 +1,88 @@
+/*
+ * Please modify "GSwifi_conf.h"
+ * ----------
+ * #define CFG_ENABLE_RTOS
+ * #define CFG_ENABLE_HTTPD
+ * #define CFG_ENABLE_WEBSOCKET
+ * //#define CFG_ENABLE_SMTP
+ * ----------
+ */
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "GSwifiInterface.h"
+
+#define SEC  GSwifi::SEC_WPA_PSK
+#define SSID "SSPD"
+#define PASS "PASSPHRASE"
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
+LocalFileSystem local("local");
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+GSwifiInterface *gs;
+
+void cgi (int cid) {
+    int i;
+    char buf[100];
+
+    led2 = 1;
+    i = gs->recv(cid, buf, sizeof(buf));
+    if (i < 0) return;
+    buf[i] = 0;
+    pc.printf("CGI %d: %s ? %s '%s' %d\r\n", cid, gs->httpdGetFilename(cid), gs->httpdGetQuerystring(cid), buf, i);
+
+    gs->send(cid, "HTTP/1.1 200 OK\r\n", 17);
+    gs->send(cid, "Content-type: text/plain\r\n", 26);
+    gs->send(cid, "\r\n", 2);
+
+    gs->send(cid, "BODY: ", 6);
+    gs->send(cid, buf, strlen(buf));
+    gs->send(cid, "\r\n", 2);
+    gs->close(cid);
+}
+
+void ws_server (int cid) {
+    int i;
+    char buf[100];
+
+    led2 = 1;
+    i = gs->recv(cid, buf, sizeof(buf));
+    if (i < 0) return;
+    buf[i] = 0;
+    pc.printf("WS %d: '%s' %d\r\n", cid, buf, i);
+
+    gs->wsSend(cid, buf, i);
+}
+
+int main () {
+
+    pc.baud(115200);
+//    pc.baud(921600);
+    printf("HTTP Server...\r\n");
+    led1 = 1;
+    gs = new GSwifiInterface(p13, p14, p12, P0_22, p21, NC, 9600);
+    gs->init(); //Use DHCP
+    if (gs->connect(SEC, SSID, PASS)) return -1; // join the network
+    printf("IP Address is %s\n", gs->getIPAddress());
+
+    printf("ready\r\n");
+    gs->httpd();
+    gs->httpdAttach("/cgi-bin/", &cgi);
+    gs->httpdAttach("/ws/", &ws_server, 1);
+    gs->httpdAttach("/test/", "/sd/www/");
+    gs->httpdAttach("/", "/local/");
+
+    for (;;) {
+        if (pc.readable()) {
+            if (pc.getc() == 'q') break;
+        }
+
+        wait_ms(50);
+        led1 = !led1;
+        led2 = 0;
+    }
+    gs->dissociate();
+    return 0;
+}
diff -r 000000000000 -r eb3c6b3965fa mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Jun 05 04:25:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#015df9e602b6
diff -r 000000000000 -r eb3c6b3965fa mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 05 04:25:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file