MiMic WebServer port to LPC1768-Mini-DK2 (Alpha ver.) *On uVision4(MDK-STD), -O2 option is required to run.
Dependencies: NySDFileSystem libMiMic mbed-rtos mbed
Fork of MbedFileServer by
main.cpp@12:e642e14ecb21, 2013-07-11 (annotated)
- Committer:
- mio
- Date:
- Thu Jul 11 14:46:27 2013 +0000
- Revision:
- 12:e642e14ecb21
- Parent:
- 11:5c1608e46104
Following Original Code Update.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 4:0a280ed0a848 | 1 | /** |
mio | 12:e642e14ecb21 | 2 | * MbedFileServer , LPC1768-MiniDK2 Port |
mio | 11:5c1608e46104 | 3 | * |
mio | 12:e642e14ecb21 | 4 | * See: |
mio | 12:e642e14ecb21 | 5 | * https://mbed.org/users/nyatla/code/libMiMic/ |
mio | 12:e642e14ecb21 | 6 | * http://nyatla.jp/mimic/wp/ |
nyatla | 4:0a280ed0a848 | 7 | * |
mio | 12:e642e14ecb21 | 8 | * 2013.7.11 : Following original update. |
mio | 12:e642e14ecb21 | 9 | * |
nyatla | 4:0a280ed0a848 | 10 | */ |
mio | 11:5c1608e46104 | 11 | |
nyatla | 5:6a2a1644ea2c | 12 | #include "mbed.h" |
nyatla | 5:6a2a1644ea2c | 13 | #include "SDFileSystem.h" |
nyatla | 0:ec1e45489427 | 14 | #include "mimic.h" |
nyatla | 10:80c05810f911 | 15 | #include "utils/PlatformInfo.h" |
mio | 11:5c1608e46104 | 16 | |
mio | 11:5c1608e46104 | 17 | #define URL_HANDLE 1 /* if you use TEST URL HANDLER */ |
mio | 11:5c1608e46104 | 18 | |
mio | 11:5c1608e46104 | 19 | DigitalOut LED_1(P3_25),LED_2(P3_26); |
mio | 11:5c1608e46104 | 20 | Serial pc(P0_2,P0_3) ; |
nyatla | 0:ec1e45489427 | 21 | |
nyatla | 3:77431c2bd9cb | 22 | /** |
mio | 11:5c1608e46104 | 23 | * sd filesystem support. |
nyatla | 3:77431c2bd9cb | 24 | */ |
mio | 11:5c1608e46104 | 25 | SDFileSystem sd(P1_24, P1_23, P1_20, P1_21,"sd"); |
mio | 11:5c1608e46104 | 26 | unsigned int p = 0; // LED TOGGLE COUNTER |
mio | 11:5c1608e46104 | 27 | |
nyatla | 0:ec1e45489427 | 28 | /** |
nyatla | 0:ec1e45489427 | 29 | * MiMic RemoteMCU httpd.<br/> |
nyatla | 5:6a2a1644ea2c | 30 | * Number of simultaneous connections:4 |
nyatla | 0:ec1e45489427 | 31 | * <p>Service list</p> |
nyatla | 0:ec1e45489427 | 32 | * <pre> |
mio | 11:5c1608e46104 | 33 | * /sd/ - mbed LocalFileSystem |
mio | 11:5c1608e46104 | 34 | * /**** - URL Handler for test |
nyatla | 0:ec1e45489427 | 35 | * </pre> |
nyatla | 0:ec1e45489427 | 36 | */ |
nyatla | 5:6a2a1644ea2c | 37 | class FsHttpd:public MiMic::Httpd |
nyatla | 0:ec1e45489427 | 38 | { |
nyatla | 0:ec1e45489427 | 39 | private: |
mio | 11:5c1608e46104 | 40 | ModUrl modurl; //basic URL parser |
nyatla | 5:6a2a1644ea2c | 41 | ModLocalFileSystem modsd; |
nyatla | 0:ec1e45489427 | 42 | public: |
mio | 12:e642e14ecb21 | 43 | FsHttpd(NetConfig& i_cfg):Httpd(i_cfg._inst.services.http_port) |
nyatla | 0:ec1e45489427 | 44 | { |
nyatla | 3:77431c2bd9cb | 45 | //bind local file system path to /local/* |
nyatla | 5:6a2a1644ea2c | 46 | modsd.setParam("sd"); |
nyatla | 0:ec1e45489427 | 47 | } |
nyatla | 0:ec1e45489427 | 48 | virtual void onRequest(HttpdConnection& i_connection) |
nyatla | 0:ec1e45489427 | 49 | { |
nyatla | 6:20dcb08e1b43 | 50 | p++; |
mio | 11:5c1608e46104 | 51 | LED_1 = p%2; |
mio | 11:5c1608e46104 | 52 | |
nyatla | 5:6a2a1644ea2c | 53 | //try to ModLocalFileSystem(SD) |
nyatla | 5:6a2a1644ea2c | 54 | if(this->modsd.execute(i_connection)){ |
nyatla | 0:ec1e45489427 | 55 | return; |
nyatla | 0:ec1e45489427 | 56 | } |
mio | 11:5c1608e46104 | 57 | |
mio | 11:5c1608e46104 | 58 | #ifdef URL_HANDLE |
mio | 11:5c1608e46104 | 59 | // URL |
mio | 11:5c1608e46104 | 60 | char url[32]; |
mio | 11:5c1608e46104 | 61 | int method; |
mio | 11:5c1608e46104 | 62 | if(this->modurl.execute(i_connection,url,32,&method)){ |
mio | 11:5c1608e46104 | 63 | //send 200 OK and requested URL |
mio | 11:5c1608e46104 | 64 | i_connection.sendHeader(200,"text/html",NULL); |
mio | 11:5c1608e46104 | 65 | i_connection.sendBodyF("Your Request No is [%d] , path is %s.",p,url); |
mio | 11:5c1608e46104 | 66 | pc.printf("%s\r\n",url) ; |
mio | 11:5c1608e46104 | 67 | return; |
mio | 11:5c1608e46104 | 68 | } |
mio | 11:5c1608e46104 | 69 | #endif |
mio | 11:5c1608e46104 | 70 | |
nyatla | 5:6a2a1644ea2c | 71 | //Otherwise, Send simple top index page. |
nyatla | 5:6a2a1644ea2c | 72 | i_connection.sendHeader(200,"text/html",NULL); |
nyatla | 5:6a2a1644ea2c | 73 | if(i_connection.isMethodType(Http::MT_GET)){ |
nyatla | 5:6a2a1644ea2c | 74 | i_connection.sendBodyF( |
nyatla | 5:6a2a1644ea2c | 75 | "<!DOCTYPE html>" |
nyatla | 5:6a2a1644ea2c | 76 | "<html lang=\"ja\">" |
nyatla | 5:6a2a1644ea2c | 77 | "<head></head>" |
nyatla | 5:6a2a1644ea2c | 78 | "<body>" |
mio | 11:5c1608e46104 | 79 | "<h1>This is MiMic Server : Mini1768DK2 Port.</h1>" |
nyatla | 5:6a2a1644ea2c | 80 | "<hr/>" |
nyatla | 5:6a2a1644ea2c | 81 | "<ul>" |
nyatla | 5:6a2a1644ea2c | 82 | "<li><a href=\"/sd/\">SDCard</a></li>" |
nyatla | 5:6a2a1644ea2c | 83 | "</ul></body>"); |
nyatla | 5:6a2a1644ea2c | 84 | } |
nyatla | 0:ec1e45489427 | 85 | } |
nyatla | 0:ec1e45489427 | 86 | }; |
nyatla | 0:ec1e45489427 | 87 | |
mio | 12:e642e14ecb21 | 88 | NetConfig cfg; //create network configulation |
nyatla | 0:ec1e45489427 | 89 | int main() |
nyatla | 0:ec1e45489427 | 90 | { |
mio | 12:e642e14ecb21 | 91 | Net net; //create a net instance. |
mio | 11:5c1608e46104 | 92 | pc.baud(9600) ; // serial port for debug |
mio | 11:5c1608e46104 | 93 | |
mio | 11:5c1608e46104 | 94 | //try to override setting by SD file. |
mio | 11:5c1608e46104 | 95 | if (cfg.loadFromFile("/sd/mimic.cfg")) { |
mio | 11:5c1608e46104 | 96 | pc.printf("Setting is Overridden by /sd/mimic.cfg\r\n") ; |
mio | 11:5c1608e46104 | 97 | } else { |
mio | 12:e642e14ecb21 | 98 | pc.printf("MY ADDR is 192.168.1.239\r\n") ; |
mio | 12:e642e14ecb21 | 99 | cfg.setEmac(0x1,0x2,0x3,0x4,0x5,0x6); |
mio | 12:e642e14ecb21 | 100 | cfg.setIpAddr(192,168,1,239) ; |
mio | 12:e642e14ecb21 | 101 | cfg.setGateway(192,168,1,1) ; |
mio | 11:5c1608e46104 | 102 | cfg.setNetMask(255,255,255,0) ; |
mio | 11:5c1608e46104 | 103 | } |
mio | 11:5c1608e46104 | 104 | |
mio | 12:e642e14ecb21 | 105 | FsHttpd httpd(cfg); //create a httpd instance. |
mio | 12:e642e14ecb21 | 106 | net.start(cfg); |
nyatla | 0:ec1e45489427 | 107 | httpd.loop(); //start httpd loop. |
nyatla | 0:ec1e45489427 | 108 | return 0; |
nyatla | 0:ec1e45489427 | 109 | } |