RPC hello world using the Wifly Interface
Dependencies: MbedJSONRpc MbedJSONValue WebSocketClient WiflyInterface mbed
Revision 0:935c9e275b45, committed 2012-08-23
- Comitter:
- samux
- Date:
- Thu Aug 23 16:08:11 2012 +0000
- Child:
- 1:516122a1a6a4
- Commit message:
- rpc hello world using wiflyinterface
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONRpc.lib Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/MbedJSONRpc/#067cb01b491e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/MbedJSONValue/#10a99cdf7846
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebSocketClient.lib Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/WebSocketClient/#466f90b7849a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WiflyInterface.lib Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/WiflyInterface/#81445de1fe27
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#include "WiflyInterface.h" +#include "Websocket.h" +#include "MbedJSONRpc.h" + +BusOut l(LED1, LED2, LED3, LED4); + +/* wifly interface: +* - p9 and p10 are for the serial communication +* - p19 is for the reset pin +* - p26 is for the connection status +* - "mbed" is the ssid of the network +* - "password" is the password +* - WPA is the security +*/ +WiflyInterface wifly(p9, p10, p19, p26, "mbed", "password", WPA); + +//websocket: configuration with sub-network = samux and mbed_id = mbed_acc +Websocket ws("ws://sockets.mbed.org/rpc/demo/mbed_led"); + +//RPC object attached to the websocket server +MbedJSONRpc rpc(&ws); + +//Test class +class Test { +public: + Test() {}; + void led(MbedJSONValue& in, MbedJSONValue& out) { + int id = in[0].get<int>(); + l = (1 << (id - 1)); + wait(0.2); + l = 0; + } +}; + +Test test; + +int main() { + + wifly.init(); //Use DHCP + wifly.connect(); + printf("IP Address is %s\n\r", wifly.getIPAddress()); + + ws.connect(); + + RPC_TYPE t; + + //------------register getAcc---------------// + if((t = rpc.registerMethod("led", &test, &Test::led)) == REGISTER_OK) + printf("led is registered\r\n"); + else + printType(t); + + //wait for incoming CALL requests + rpc.work(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Aug 23 16:08:11 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file