updated RPC command to match javascripting language
Dependencies: EthernetInterface HTTPServerExample mbed-rpc mbed-rtos mbed
Fork of EthHTTPServer by
Revision 6:fde802d0f163, committed 2013-12-06
- Comitter:
- sammacjunkie
- Date:
- Fri Dec 06 18:20:02 2013 +0000
- Parent:
- 5:c5c2f7026638
- Child:
- 7:a6e27f5a8d74
- Commit message:
- updated example code;
Changed in this revision
HTTPServer.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPServer.lib Sat Aug 17 17:00:35 2013 +0000 +++ b/HTTPServer.lib Fri Dec 06 18:20:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/leihen/code/HTTPServer/#cc3f5c53d0d5 +http://mbed.org/users/sammacjunkie/code/HTTPServerExample/#492d23f9644d
--- a/main.cpp Sat Aug 17 17:00:35 2013 +0000 +++ b/main.cpp Fri Dec 06 18:20:02 2013 +0000 @@ -5,8 +5,7 @@ #include "RpcHandler.h" #include "mbed_rpc.h" -#define ALTERNATIVE -//#undef ALTERNATIVE + // Use LED1 to indicate that the main loop is still executing DigitalOut myled(LED1); @@ -17,39 +16,31 @@ // Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. LocalFileSystem local("local"); - -#ifdef ALTERNATIVE // Create the EthernetInterface. This is optional, please see the documentation of HTTP Server's start method. EthernetInterface eth; -#endif +//Make these variables accessible over RPC by attaching them to an RPCVariable +int Request = 0; +RPCVariable<int> RPCRequest(&Request, "Request"); int main() { - pc.baud(460800); - RPC::add_rpc_class<RpcDigitalOut>(); - HTTPFsRequestHandler::mount("/local/", "/"); - svr.addHandler<HTTPFsRequestHandler>("/"); - svr.addHandler<HTTPRpcRequestHandler>("/RPC"); + HTTPFsRequestHandler::mount("/local/", "/"); // Mount /local/ filesystem as root web path / + svr.addHandler<HTTPFsRequestHandler>("/"); // Serve all default HTTP requests + svr.addHandler<HTTPRpcRequestHandler>("/RPC"); // Serve all RPC requests -#ifdef ALTERNATIVE - // Initialize the EthernetInterface and initiate a connection using DHCP. + + // Initialize the EthernetInterface and initiate a connection using default DHCP. eth.init(); eth.connect(); if (!svr.start(80, ð)) { -#else - if (!svr.start()) { -#endif error("Server not starting !"); exit(0); } while(1) { svr.poll(); - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + myled = Request; } }