updated RPC command to match javascripting language
Dependencies: EthernetInterface HTTPServerExample mbed-rpc mbed-rtos mbed
Fork of EthHTTPServer by
main.cpp@7:a6e27f5a8d74, 2013-12-06 (annotated)
- Committer:
- sammacjunkie
- Date:
- Fri Dec 06 18:29:25 2013 +0000
- Revision:
- 7:a6e27f5a8d74
- Parent:
- 6:fde802d0f163
updated RPC command
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 | 5:c5c2f7026638 | 5 | #include "RpcHandler.h" |
leihen | 5:c5c2f7026638 | 6 | #include "mbed_rpc.h" |
leihen | 0:28a67716dfec | 7 | |
sammacjunkie | 6:fde802d0f163 | 8 | |
leihen | 0:28a67716dfec | 9 | |
leihen | 1:6cbd17e628f1 | 10 | // Use LED1 to indicate that the main loop is still executing |
leihen | 0:28a67716dfec | 11 | DigitalOut myled(LED1); |
leihen | 1:6cbd17e628f1 | 12 | // Use the serial connection 'pc' to dump debug information |
leihen | 0:28a67716dfec | 13 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 1:6cbd17e628f1 | 14 | // Instantiate a HTTPServer to handle incoming requests |
leihen | 0:28a67716dfec | 15 | HTTPServer svr; |
leihen | 1:6cbd17e628f1 | 16 | // Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. |
leihen | 1:6cbd17e628f1 | 17 | LocalFileSystem local("local"); |
leihen | 0:28a67716dfec | 18 | |
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 | |
sammacjunkie | 6:fde802d0f163 | 22 | //Make these variables accessible over RPC by attaching them to an RPCVariable |
sammacjunkie | 6:fde802d0f163 | 23 | int Request = 0; |
sammacjunkie | 6:fde802d0f163 | 24 | RPCVariable<int> RPCRequest(&Request, "Request"); |
leihen | 0:28a67716dfec | 25 | |
leihen | 0:28a67716dfec | 26 | int main() { |
leihen | 0:28a67716dfec | 27 | |
sammacjunkie | 6:fde802d0f163 | 28 | HTTPFsRequestHandler::mount("/local/", "/"); // Mount /local/ filesystem as root web path / |
sammacjunkie | 6:fde802d0f163 | 29 | svr.addHandler<HTTPFsRequestHandler>("/"); // Serve all default HTTP requests |
sammacjunkie | 7:a6e27f5a8d74 | 30 | svr.addHandler<HTTPRpcRequestHandler>("/rpc"); // Serve all RPC requests |
leihen | 5:c5c2f7026638 | 31 | |
sammacjunkie | 6:fde802d0f163 | 32 | |
sammacjunkie | 6:fde802d0f163 | 33 | // Initialize the EthernetInterface and initiate a connection using default DHCP. |
leihen | 1:6cbd17e628f1 | 34 | eth.init(); |
leihen | 1:6cbd17e628f1 | 35 | eth.connect(); |
leihen | 1:6cbd17e628f1 | 36 | |
leihen | 1:6cbd17e628f1 | 37 | if (!svr.start(80, ð)) { |
leihen | 0:28a67716dfec | 38 | error("Server not starting !"); |
leihen | 0:28a67716dfec | 39 | exit(0); |
leihen | 0:28a67716dfec | 40 | } |
leihen | 0:28a67716dfec | 41 | |
leihen | 0:28a67716dfec | 42 | while(1) { |
leihen | 0:28a67716dfec | 43 | svr.poll(); |
sammacjunkie | 6:fde802d0f163 | 44 | myled = Request; |
leihen | 0:28a67716dfec | 45 | } |
leihen | 0:28a67716dfec | 46 | } |