updated RPC command to match javascripting language
Dependencies: EthernetInterface HTTPServerExample mbed-rpc mbed-rtos mbed
Fork of EthHTTPServer by
main.cpp@1:6cbd17e628f1, 2013-08-17 (annotated)
- Committer:
- leihen
- Date:
- Sat Aug 17 12:32:09 2013 +0000
- Revision:
- 1:6cbd17e628f1
- Parent:
- 0:28a67716dfec
- Child:
- 5:c5c2f7026638
Updated the example to reflect the modification of the HTTPServer library, which allows to provide an EthernetInterface object at the time of starting the HTTPServer. This allows to make Connections and perform other Network Tasks before svr start.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:28a67716dfec | 1 | #include "mbed.h" |
leihen | 0:28a67716dfec | 2 | #include "HTTPServer.h" |
leihen | 0:28a67716dfec | 3 | #include "FsHandler.h" |
leihen | 0:28a67716dfec | 4 | #include "LocalFileSystem.h" |
leihen | 0:28a67716dfec | 5 | |
leihen | 1:6cbd17e628f1 | 6 | #define ALTERNATIVE |
leihen | 1:6cbd17e628f1 | 7 | //#undef ALTERNATIVE |
leihen | 0:28a67716dfec | 8 | |
leihen | 1:6cbd17e628f1 | 9 | // Use LED1 to indicate that the main loop is still executing |
leihen | 0:28a67716dfec | 10 | DigitalOut myled(LED1); |
leihen | 1:6cbd17e628f1 | 11 | // Use the serial connection 'pc' to dump debug information |
leihen | 0:28a67716dfec | 12 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 1:6cbd17e628f1 | 13 | // Instantiate a HTTPServer to handle incoming requests |
leihen | 0:28a67716dfec | 14 | HTTPServer svr; |
leihen | 1:6cbd17e628f1 | 15 | // Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. |
leihen | 1:6cbd17e628f1 | 16 | LocalFileSystem local("local"); |
leihen | 0:28a67716dfec | 17 | |
leihen | 1:6cbd17e628f1 | 18 | #ifdef ALTERNATIVE |
leihen | 1:6cbd17e628f1 | 19 | // Create the EthernetInterface. This is optional, please see the documentation of HTTP Server's start method. |
leihen | 1:6cbd17e628f1 | 20 | EthernetInterface eth; |
leihen | 1:6cbd17e628f1 | 21 | #endif |
leihen | 1:6cbd17e628f1 | 22 | |
leihen | 0:28a67716dfec | 23 | |
leihen | 0:28a67716dfec | 24 | int main() { |
leihen | 0:28a67716dfec | 25 | |
leihen | 0:28a67716dfec | 26 | pc.baud(460800); |
leihen | 0:28a67716dfec | 27 | HTTPFsRequestHandler::mount("/local/", "/"); |
leihen | 0:28a67716dfec | 28 | svr.addHandler<HTTPFsRequestHandler>("/"); |
leihen | 0:28a67716dfec | 29 | |
leihen | 1:6cbd17e628f1 | 30 | #ifdef ALTERNATIVE |
leihen | 1:6cbd17e628f1 | 31 | // Initialize the EthernetInterface and initiate a connection using DHCP. |
leihen | 1:6cbd17e628f1 | 32 | eth.init(); |
leihen | 1:6cbd17e628f1 | 33 | eth.connect(); |
leihen | 1:6cbd17e628f1 | 34 | |
leihen | 1:6cbd17e628f1 | 35 | if (!svr.start(80, ð)) { |
leihen | 1:6cbd17e628f1 | 36 | #else |
leihen | 0:28a67716dfec | 37 | if (!svr.start()) { |
leihen | 1:6cbd17e628f1 | 38 | #endif |
leihen | 0:28a67716dfec | 39 | error("Server not starting !"); |
leihen | 0:28a67716dfec | 40 | exit(0); |
leihen | 0:28a67716dfec | 41 | } |
leihen | 0:28a67716dfec | 42 | |
leihen | 0:28a67716dfec | 43 | while(1) { |
leihen | 0:28a67716dfec | 44 | svr.poll(); |
leihen | 0:28a67716dfec | 45 | myled = 1; |
leihen | 0:28a67716dfec | 46 | wait(0.2); |
leihen | 0:28a67716dfec | 47 | myled = 0; |
leihen | 0:28a67716dfec | 48 | wait(0.2); |
leihen | 0:28a67716dfec | 49 | } |
leihen | 0:28a67716dfec | 50 | } |