HTTPサーバのサンプル
Dependencies: EthernetNetIf HTTPServer mbed
main.cpp@0:a3e48855b378, 2015-09-14 (annotated)
- Committer:
- jksoft
- Date:
- Mon Sep 14 14:59:01 2015 +0000
- Revision:
- 0:a3e48855b378
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:a3e48855b378 | 1 | #include "mbed.h" |
jksoft | 0:a3e48855b378 | 2 | #include "EthernetNetIf.h" |
jksoft | 0:a3e48855b378 | 3 | #include "HTTPServer.h" |
jksoft | 0:a3e48855b378 | 4 | |
jksoft | 0:a3e48855b378 | 5 | EthernetNetIf eth; |
jksoft | 0:a3e48855b378 | 6 | HTTPServer svr; |
jksoft | 0:a3e48855b378 | 7 | DigitalOut led1(LED1); |
jksoft | 0:a3e48855b378 | 8 | DigitalOut led2(LED2, "led2"); |
jksoft | 0:a3e48855b378 | 9 | AnalogIn ain(p15,"tmp"); |
jksoft | 0:a3e48855b378 | 10 | LocalFileSystem fs("webfs"); |
jksoft | 0:a3e48855b378 | 11 | |
jksoft | 0:a3e48855b378 | 12 | int main() { |
jksoft | 0:a3e48855b378 | 13 | |
jksoft | 0:a3e48855b378 | 14 | printf("Setting up...\n"); |
jksoft | 0:a3e48855b378 | 15 | |
jksoft | 0:a3e48855b378 | 16 | EthernetErr ethErr = eth.setup(); |
jksoft | 0:a3e48855b378 | 17 | |
jksoft | 0:a3e48855b378 | 18 | if(ethErr) { |
jksoft | 0:a3e48855b378 | 19 | printf("Error %d in setup.\n", ethErr); |
jksoft | 0:a3e48855b378 | 20 | return -1; |
jksoft | 0:a3e48855b378 | 21 | } |
jksoft | 0:a3e48855b378 | 22 | printf("Setup OK\n"); |
jksoft | 0:a3e48855b378 | 23 | |
jksoft | 0:a3e48855b378 | 24 | |
jksoft | 0:a3e48855b378 | 25 | FSHandler::mount("/webfs", "/"); |
jksoft | 0:a3e48855b378 | 26 | svr.addHandler<RPCHandler>("/rpc"); |
jksoft | 0:a3e48855b378 | 27 | svr.addHandler<FSHandler>("/"); |
jksoft | 0:a3e48855b378 | 28 | svr.bind(80); |
jksoft | 0:a3e48855b378 | 29 | |
jksoft | 0:a3e48855b378 | 30 | printf("Listening...\n"); |
jksoft | 0:a3e48855b378 | 31 | |
jksoft | 0:a3e48855b378 | 32 | Timer tm; |
jksoft | 0:a3e48855b378 | 33 | tm.start(); |
jksoft | 0:a3e48855b378 | 34 | |
jksoft | 0:a3e48855b378 | 35 | while(true) |
jksoft | 0:a3e48855b378 | 36 | { |
jksoft | 0:a3e48855b378 | 37 | Net::poll(); |
jksoft | 0:a3e48855b378 | 38 | if(tm.read()>.5) |
jksoft | 0:a3e48855b378 | 39 | { |
jksoft | 0:a3e48855b378 | 40 | led1=!led1; |
jksoft | 0:a3e48855b378 | 41 | tm.start(); |
jksoft | 0:a3e48855b378 | 42 | } |
jksoft | 0:a3e48855b378 | 43 | } |
jksoft | 0:a3e48855b378 | 44 | return 0; |
jksoft | 0:a3e48855b378 | 45 | } |