Example using MbedJSONRpc: call distant method
Dependencies: MbedJSONRpc EthernetNetIf mbed DNSResolver MbedJSONValue
main.cpp@2:d439eefcc605, 2011-10-03 (annotated)
- Committer:
- samux
- Date:
- Mon Oct 03 09:00:22 2011 +0000
- Revision:
- 2:d439eefcc605
- Parent:
- 0:b7259f428f5f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:b7259f428f5f | 1 | #include "mbed.h" |
samux | 0:b7259f428f5f | 2 | #include "MbedJSONRpc.h" |
samux | 0:b7259f428f5f | 3 | #include "MbedJSONValue.h" |
samux | 0:b7259f428f5f | 4 | #include "Websocket.h" |
samux | 0:b7259f428f5f | 5 | |
samux | 0:b7259f428f5f | 6 | Serial pc(USBTX, USBRX); |
samux | 0:b7259f428f5f | 7 | |
samux | 0:b7259f428f5f | 8 | //websocket: configuration with sub-network = samux and mbed_id = mbed_acc |
samux | 2:d439eefcc605 | 9 | Websocket webs("ws://sockets.mbed.org/rpc/samux/mbed_client"); |
samux | 0:b7259f428f5f | 10 | |
samux | 0:b7259f428f5f | 11 | //RPC object attached to the websocket server |
samux | 0:b7259f428f5f | 12 | MbedJSONRpc rpc(&webs); |
samux | 0:b7259f428f5f | 13 | |
samux | 0:b7259f428f5f | 14 | int main() { |
samux | 0:b7259f428f5f | 15 | |
samux | 2:d439eefcc605 | 16 | pc.printf("\x1B[2J"); |
samux | 2:d439eefcc605 | 17 | pc.printf("\x1B[H"); |
samux | 2:d439eefcc605 | 18 | |
samux | 0:b7259f428f5f | 19 | RPC_TYPE t; |
samux | 0:b7259f428f5f | 20 | |
samux | 0:b7259f428f5f | 21 | //in: argument for the distant method (here empty) |
samux | 0:b7259f428f5f | 22 | //out results of the distant method (accelerometers values) |
samux | 0:b7259f428f5f | 23 | MbedJSONValue in, out; |
samux | 0:b7259f428f5f | 24 | |
samux | 2:d439eefcc605 | 25 | while (!webs.connect()); |
samux | 0:b7259f428f5f | 26 | |
samux | 0:b7259f428f5f | 27 | //CALL getAcc on mbed_acc |
samux | 0:b7259f428f5f | 28 | if ((t = rpc.call("getAcc", "mbed_acc", in, out)) == CALL_OK) { |
samux | 0:b7259f428f5f | 29 | printf("call success\r\n"); |
samux | 0:b7259f428f5f | 30 | printf("acc_x: %d\r\n", out[0].get<int>()); |
samux | 0:b7259f428f5f | 31 | printf("acc_y: %d\r\n", out[1].get<int>()); |
samux | 0:b7259f428f5f | 32 | printf("acc_z: %d\r\n", out[2].get<int>()); |
samux | 0:b7259f428f5f | 33 | } else |
samux | 0:b7259f428f5f | 34 | printType(t); |
samux | 0:b7259f428f5f | 35 | } |