Low Memory HTTP Server (LPC1114FN28 + WIZ820io)
Dependencies: Tiny-HTTPD WIZ820ioInterface mbed-rpc mbed
Fork of HTTPD_sample by
Revision 2:3a7574ace580, committed 2014-02-04
- Comitter:
- ban4jp
- Date:
- Tue Feb 04 03:26:08 2014 +0000
- Parent:
- 1:2971dd3e5168
- Commit message:
- LPC1114FN28 + WIZ820io support.
Changed in this revision
diff -r 2971dd3e5168 -r 3a7574ace580 EthernetInterface.lib --- a/EthernetInterface.lib Wed Nov 13 06:59:58 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
diff -r 2971dd3e5168 -r 3a7574ace580 HTTPD.lib --- a/HTTPD.lib Wed Nov 13 06:59:58 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/okini3939/code/HTTPD/#d18dff347122
diff -r 2971dd3e5168 -r 3a7574ace580 Tiny-HTTPD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tiny-HTTPD.lib Tue Feb 04 03:26:08 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/ban4jp/code/Tiny-HTTPD/#905fe8dfebd6
diff -r 2971dd3e5168 -r 3a7574ace580 WIZ820ioInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WIZ820ioInterface.lib Tue Feb 04 03:26:08 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/ban4jp/code/WIZ820ioInterface/#6ff41cd782f5
diff -r 2971dd3e5168 -r 3a7574ace580 main.cpp --- a/main.cpp Wed Nov 13 06:59:58 2013 +0000 +++ b/main.cpp Tue Feb 04 03:26:08 2014 +0000 @@ -1,16 +1,46 @@ #include "mbed.h" -#include "rtos.h" -#include "EthernetInterface.h" +#include "WIZ820ioInterface.h" #include "mbed_rpc.h" #include "HTTPD.h" -EthernetInterface *eth; +SPI *spi; +WIZ820ioInterface *eth; HTTPD *httpd; +#if defined(TARGET_LPC1768) Serial pc(USBTX, USBRX); LocalFileSystem local("local"); DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); +#elif defined(TARGET_LPC1114) +Serial pc(dp16,dp15); + +#endif + +const char* const index_page = + "<html>" + "<body>" + "<h1>Tiny HTTP Server</h1>" + "<h2>RPC</h2>" + "<a href=\"/rpc/DigitalOut/new%20LED1%20myled\">/rpc/DigitalOut/new LED1 myled</a><br><br>" + "<a href=\"/rpc/myled/write%200\">/rpc/myled/write 0</a><br><br>" + "<a href=\"/rpc/myled/write%201\">/rpc/myled/write 1</a><br><br>" + "</body>" + "</html>"; + +void callback_static (int id) { + char buf[256]; + + strcpy(buf, httpd->getFilename(id)); + printf("static %d %s\r\n", id, buf); + + if (strcmp(buf, "") == 0 || strcmp(buf, "index.html") == 0) { + httpd->send(id, index_page, strlen(index_page), "Content-Type: text/html\r\n"); + } else { + httpd->httpdError(id, 404); + } +} + void callback_cgi (int id) { int i, n; char buf[256]; @@ -54,14 +84,30 @@ } int main () { + int ret; - pc.baud(115200); + //pc.baud(115200); + pc.baud(9600); 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"); - if (eth->connect()) return -1; +#if defined(TARGET_LPC1768) + spi = new SPI(p5, p6, p7); // mosi, miso, sclk + spi->frequency(4000000); // 4MHz + eth = new WIZ820ioInterface(spi, p21, p22); // spi, cs, reset +#elif defined(TARGET_LPC1114) + spi = new SPI(dp2, dp1, dp6); // mosi, miso, sclk + spi->frequency(4000000); // 4MHz + eth = new WIZ820ioInterface(spi, dp25, dp26); // spi, cs, reset +#endif + + eth->init(); //Use DHCP +// eth->init("192.168.1.2", "255.255.255.0", "192.168.1.1"); + + ret = eth->connect(); + if (ret) { + printf("connect error %d", ret); + return -1; + } printf("IP Address is %s\r\n", eth->getIPAddress()); // RPC::add_rpc_class<RpcAnalogIn>(); @@ -75,11 +121,19 @@ httpd->attach("/cgi-bin/", &callback_cgi); httpd->attach("/ws/", &callback_ws); httpd->attach("/rpc/", &callback_rpc); - httpd->attach("/", "/local/"); +#if defined(TARGET_LPC1768) + httpd->attach("/local/", "/local/"); +#endif + httpd->attach("/", &callback_static); httpd->start(80); printf("httpd ready\r\n"); +#if defined(TARGET_LPC1768) led1 = 1; +#endif for (;;) { + httpd->poll(); + + //printf("poll-loop\r\n"); } }
diff -r 2971dd3e5168 -r 3a7574ace580 mbed-rtos.lib --- a/mbed-rtos.lib Wed Nov 13 06:59:58 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
diff -r 2971dd3e5168 -r 3a7574ace580 mbed.bld --- a/mbed.bld Wed Nov 13 06:59:58 2013 +0000 +++ b/mbed.bld Tue Feb 04 03:26:08 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43 \ No newline at end of file