Example using MbedJSONRpc: call distant method
Dependencies: MbedJSONRpc EthernetNetIf mbed DNSResolver MbedJSONValue
Revision 0:b7259f428f5f, committed 2011-09-22
- Comitter:
- samux
- Date:
- Thu Sep 22 12:31:37 2011 +0000
- Child:
- 1:5929c085acec
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DNSResolver.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hlipka/code/DNSResolver/#097d4993dd1e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONRpc.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/MbedJSONRpc/#88e1902947e5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/MbedJSONValue/#10a99cdf7846
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Websocket.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/Websocket/#2214f1e5d4a3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wifly.lib Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/Wifly/#6eb90004d92a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" +#include "MbedJSONRpc.h" +#include "MbedJSONValue.h" +#include "Websocket.h" + +Serial pc(USBTX, USBRX); + +//websocket: configuration with sub-network = samux and mbed_id = mbed_acc +Websocket webs("ws://sockets.mbed.org:888/ws/samux/client"); + +//RPC object attached to the websocket server +MbedJSONRpc rpc(&webs); + +int main() { + + RPC_TYPE t; + + //in: argument for the distant method (here empty) + //out results of the distant method (accelerometers values) + MbedJSONValue in, out; + + while (!webs.connect()) + pc.printf("cannot connect websocket, retrying\r\n"); + + //CALL getAcc on mbed_acc + if ((t = rpc.call("getAcc", "mbed_acc", in, out)) == CALL_OK) { + printf("call success\r\n"); + printf("acc_x: %d\r\n", out[0].get<int>()); + printf("acc_y: %d\r\n", out[1].get<int>()); + printf("acc_z: %d\r\n", out[2].get<int>()); + } else + printType(t); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Sep 22 12:31:37 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912