Ton van de Pol
/
Elmicro_Testbed_NetHttpServer
HttpServerExample.cpp@1:fae5b4e9987e, 2011-06-24 (annotated)
- Committer:
- TP
- Date:
- Fri Jun 24 20:41:52 2011 +0000
- Revision:
- 1:fae5b4e9987e
- Parent:
- 0:a4a5adb694e5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TP | 0:a4a5adb694e5 | 1 | #include "mbed.h" |
TP | 0:a4a5adb694e5 | 2 | #include "EthernetNetIf.h" |
TP | 0:a4a5adb694e5 | 3 | #include "HttpServer.h" |
TP | 0:a4a5adb694e5 | 4 | #include "TextLCD.h" |
TP | 1:fae5b4e9987e | 5 | //#include "HTTPRPC.h" |
TP | 1:fae5b4e9987e | 6 | //#include "HTTPFS.h" |
TP | 0:a4a5adb694e5 | 7 | |
TP | 0:a4a5adb694e5 | 8 | DigitalOut led1(LED1, "led1"); |
TP | 0:a4a5adb694e5 | 9 | DigitalOut led2(LED2, "led2"); |
TP | 0:a4a5adb694e5 | 10 | DigitalOut led3(LED3, "led3"); |
TP | 0:a4a5adb694e5 | 11 | DigitalOut led4(LED4, "led4"); |
TP | 1:fae5b4e9987e | 12 | AnalogIn ain(p15, "potm"); |
TP | 0:a4a5adb694e5 | 13 | |
TP | 0:a4a5adb694e5 | 14 | LocalFileSystem fs("webfs"); |
TP | 0:a4a5adb694e5 | 15 | |
TP | 0:a4a5adb694e5 | 16 | DigitalOut rw(p25); |
TP | 0:a4a5adb694e5 | 17 | TextLCD lcd(p26,p24,p23,p22,p20,p19, TextLCD::LCD20x4); |
TP | 0:a4a5adb694e5 | 18 | |
TP | 0:a4a5adb694e5 | 19 | |
TP | 1:fae5b4e9987e | 20 | EthernetNetIf eth; |
TP | 0:a4a5adb694e5 | 21 | HttpServer svr; |
TP | 0:a4a5adb694e5 | 22 | |
TP | 0:a4a5adb694e5 | 23 | int main() { |
TP | 1:fae5b4e9987e | 24 | rw = 0; |
TP | 1:fae5b4e9987e | 25 | |
TP | 1:fae5b4e9987e | 26 | Base::add_rpc_class<DigitalOut>(); |
TP | 1:fae5b4e9987e | 27 | Base::add_rpc_class<AnalogIn>(); |
TP | 1:fae5b4e9987e | 28 | lcd.cls(); |
TP | 1:fae5b4e9987e | 29 | lcd.printf("Setting up.."); |
TP | 1:fae5b4e9987e | 30 | EthernetErr ethErr = eth.setup(); |
TP | 1:fae5b4e9987e | 31 | if (ethErr) { |
TP | 1:fae5b4e9987e | 32 | lcd.printf("Error %d\n", ethErr); |
TP | 1:fae5b4e9987e | 33 | return -1; |
TP | 1:fae5b4e9987e | 34 | } |
TP | 1:fae5b4e9987e | 35 | lcd.printf("OK\n"); |
TP | 1:fae5b4e9987e | 36 | IpAddr addr = eth.getIp(); |
TP | 0:a4a5adb694e5 | 37 | |
TP | 1:fae5b4e9987e | 38 | // svr.addHandler(new HttpServer()); |
TP | 1:fae5b4e9987e | 39 | svr.addHandler<SimpleHandler>("/hello"); |
TP | 1:fae5b4e9987e | 40 | svr.addHandler<RpcHandler>("/rpc"); |
TP | 1:fae5b4e9987e | 41 | svr.addHandler<FSHandler>(""); //Default handler |
TP | 1:fae5b4e9987e | 42 | //Zet demo.htm in de root van de mbed. |
TP | 1:fae5b4e9987e | 43 | svr.bind(80); |
TP | 1:fae5b4e9987e | 44 | |
TP | 1:fae5b4e9987e | 45 | lcd.printf("Listening at http://%3d.%3d.%3d.%3d/webfs/demo.htm", addr[0], addr[1], addr[2], addr[3]); |
TP | 1:fae5b4e9987e | 46 | |
TP | 1:fae5b4e9987e | 47 | Timer tm; |
TP | 1:fae5b4e9987e | 48 | tm.start(); |
TP | 1:fae5b4e9987e | 49 | //Listen indefinitely |
TP | 1:fae5b4e9987e | 50 | while (true) { |
TP | 1:fae5b4e9987e | 51 | Net::poll(); |
TP | 1:fae5b4e9987e | 52 | if (tm.read()>.5) { |
TP | 1:fae5b4e9987e | 53 | led1=!led1; //Show that we are alive |
TP | 1:fae5b4e9987e | 54 | tm.start(); |
TP | 1:fae5b4e9987e | 55 | } |
TP | 0:a4a5adb694e5 | 56 | } |
TP | 1:fae5b4e9987e | 57 | |
TP | 0:a4a5adb694e5 | 58 | |
TP | 0:a4a5adb694e5 | 59 | } |