![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Programme + libraires serveur capteur web
Dependencies: EthernetNetIf Serveur_web_capteur mbed
Fork of HTTPServerExample by
HTTPServerExample.cpp@1:114e347434c1, 2010-06-18 (annotated)
- Committer:
- donatien
- Date:
- Fri Jun 18 09:49:11 2010 +0000
- Revision:
- 1:114e347434c1
- Parent:
- 0:0b1369ae8b74
- Child:
- 3:e851c29d398d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0b1369ae8b74 | 1 | #include "mbed.h" |
donatien | 0:0b1369ae8b74 | 2 | #include "EthernetNetIf.h" |
donatien | 0:0b1369ae8b74 | 3 | #include "HTTPServer.h" |
donatien | 0:0b1369ae8b74 | 4 | |
donatien | 0:0b1369ae8b74 | 5 | DigitalOut led1(LED1, "led1"); |
donatien | 0:0b1369ae8b74 | 6 | DigitalOut led2(LED2, "led2"); |
donatien | 0:0b1369ae8b74 | 7 | DigitalOut led3(LED3, "led3"); |
donatien | 0:0b1369ae8b74 | 8 | DigitalOut led4(LED4, "led4"); |
donatien | 0:0b1369ae8b74 | 9 | |
donatien | 0:0b1369ae8b74 | 10 | LocalFileSystem fs("webfs"); |
donatien | 0:0b1369ae8b74 | 11 | |
donatien | 0:0b1369ae8b74 | 12 | EthernetNetIf eth; |
donatien | 0:0b1369ae8b74 | 13 | HTTPServer svr; |
donatien | 0:0b1369ae8b74 | 14 | |
donatien | 0:0b1369ae8b74 | 15 | int main() { |
donatien | 0:0b1369ae8b74 | 16 | Base::add_rpc_class<DigitalOut>(); |
donatien | 0:0b1369ae8b74 | 17 | |
donatien | 1:114e347434c1 | 18 | printf("Setting up...\n"); |
donatien | 0:0b1369ae8b74 | 19 | EthernetErr ethErr = eth.setup(); |
donatien | 0:0b1369ae8b74 | 20 | if(ethErr) |
donatien | 0:0b1369ae8b74 | 21 | { |
donatien | 0:0b1369ae8b74 | 22 | printf("Error %d in setup.\n", ethErr); |
donatien | 0:0b1369ae8b74 | 23 | return -1; |
donatien | 0:0b1369ae8b74 | 24 | } |
donatien | 0:0b1369ae8b74 | 25 | printf("Setup OK\n"); |
donatien | 0:0b1369ae8b74 | 26 | |
donatien | 0:0b1369ae8b74 | 27 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
donatien | 0:0b1369ae8b74 | 28 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
donatien | 0:0b1369ae8b74 | 29 | |
donatien | 0:0b1369ae8b74 | 30 | svr.addHandler<SimpleHandler>("/hello"); |
donatien | 0:0b1369ae8b74 | 31 | svr.addHandler<RPCHandler>("/rpc"); |
donatien | 0:0b1369ae8b74 | 32 | svr.addHandler<FSHandler>("/files"); |
donatien | 0:0b1369ae8b74 | 33 | svr.addHandler<FSHandler>("/"); //Default handler |
donatien | 0:0b1369ae8b74 | 34 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
donatien | 0:0b1369ae8b74 | 35 | |
donatien | 0:0b1369ae8b74 | 36 | svr.bind(80); |
donatien | 0:0b1369ae8b74 | 37 | |
donatien | 0:0b1369ae8b74 | 38 | printf("Listening...\n"); |
donatien | 0:0b1369ae8b74 | 39 | |
donatien | 0:0b1369ae8b74 | 40 | Timer tm; |
donatien | 0:0b1369ae8b74 | 41 | tm.start(); |
donatien | 0:0b1369ae8b74 | 42 | //Listen indefinitely |
donatien | 0:0b1369ae8b74 | 43 | while(true) |
donatien | 0:0b1369ae8b74 | 44 | { |
donatien | 0:0b1369ae8b74 | 45 | Net::poll(); |
donatien | 0:0b1369ae8b74 | 46 | if(tm.read()>.5) |
donatien | 0:0b1369ae8b74 | 47 | { |
donatien | 0:0b1369ae8b74 | 48 | led1=!led1; //Show that we are alive |
donatien | 0:0b1369ae8b74 | 49 | tm.start(); |
donatien | 0:0b1369ae8b74 | 50 | } |
donatien | 0:0b1369ae8b74 | 51 | } |
donatien | 0:0b1369ae8b74 | 52 | |
donatien | 0:0b1369ae8b74 | 53 | return 0; |
donatien | 0:0b1369ae8b74 | 54 | |
donatien | 0:0b1369ae8b74 | 55 | } |