gs fan
/
GSwifi_httpd
HTTP server for GSwifi see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Diff: main.cpp
- Revision:
- 1:d0ec28e041d6
- Parent:
- 0:540fed81e29b
- Child:
- 2:15b6f6754f76
--- a/main.cpp Thu Nov 01 03:06:04 2012 +0000 +++ b/main.cpp Thu Nov 08 01:52:13 2012 +0000 @@ -1,28 +1,71 @@ +/* + * HTTP server for GSwifi + * + * create the index.htm for LocalFileSystem. + * access http://IP address/ , http://IP address/test/ + * CGI is http://IP address/cgi-bin/hoge?hage + */ + #include "mbed.h" #include "GSwifi.h" #define PORT 80 -#define SECURE GSSEC_WPA_PSK -#define SSID "SSID" -#define PASS "passkey" +#define SECURE GSSEC_WPA2_PSK +//#define SSID "SSID" +//#define PASS "passkey" +#define SSID "ROBOBA" +#define PASS "roboba1234567" -GSwifi gs(p13, p14); // TX, RX (no flow control) -// GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS +// GSwifi gs(p13, p14); // TX, RX (no flow control) +GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS +DigitalOut gs_reset(p9); LocalFileSystem local("local"); Serial pc(USBTX, USBRX); DigitalOut led1(LED1), led2(LED2); +void cgi (int cid, GS_httpd *gshttpd) { + int i; + + pc.printf("CGI %d: %s ? %s '%s' %d\r\n", cid, gshttpd->file, gshttpd->query, gshttpd->buf, gshttpd->len); + + 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, "REQUEST_METHOD: ", 16); + if (gshttpd[cid].type == GSPROT_HTTPGET) { + gs.send(cid, "GET\r\n", 5); + } else { + gs.send(cid, "POST\r\n", 6); + } + gs.send(cid, "SCRIPT_NAME: ", 13); + gs.send(cid, gshttpd->file, strlen(gshttpd->file)); + gs.send(cid, "\r\n", 2); + gs.send(cid, "QUERY_STRING: ", 14); + gs.send(cid, gshttpd->query, strlen(gshttpd->query)); + gs.send(cid, "\r\n", 2); + gs.send(cid, "POST_BODY: ", 11); + gs.send(cid, gshttpd->buf, strlen(gshttpd->buf)); + gs.send(cid, "\r\n", 2); + +} + int main () { IpAddr ipaddr, netmask, gateway, nameserver; Host host; + gs_reset = 0; + wait_ms(100); + gs_reset = 1; + wait_ms(500); + led1 = 1; pc.baud(115200); - pc.printf("connect\r\n"); + pc.printf("connecting...\r\n"); if (gs.connect(SECURE, SSID, PASS)) { return -1; } @@ -32,8 +75,9 @@ led2 = 1; pc.printf("httpd\r\n"); gs.httpd(PORT); - gs.attach_httpd("/test/", "/local/sample/"); - gs.attach_httpd("/example/", "/local/"); + gs.attach_httpd("/test/", "/local/"); + gs.attach_httpd("/example/", "/local/sample/"); + gs.attach_httpd("/cgi-bin/", &cgi); gs.attach_httpd("/", "/local/"); for (;;) {