Example using MbedJSONRpc: call distant method
Dependencies: MbedJSONRpc EthernetNetIf mbed DNSResolver MbedJSONValue
Diff: main.cpp
- Revision:
- 0:b7259f428f5f
- Child:
- 2:d439eefcc605
--- /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); +}