RPC hello world over Ethernet
Dependencies: EthernetInterface MbedJSONRpc MbedJSONValue WebSocketClient mbed-rtos mbed
Revision 0:6538aa30a040, committed 2012-08-24
- Comitter:
- samux
- Date:
- Fri Aug 24 14:57:31 2012 +0000
- Commit message:
- rpc hello world with the mbed official EthernetInterface
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Fri Aug 24 14:57:31 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONRpc.lib Fri Aug 24 14:57:31 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 Fri Aug 24 14:57:31 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 Fri Aug 24 14:57:31 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/main.cpp Fri Aug 24 14:57:31 2012 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "MbedJSONRpc.h"
+#include "MbedJSONValue.h"
+#include "EthernetInterface.h"
+#include "Websocket.h"
+
+Serial pc(USBTX, USBRX);
+BusOut l(LED1, LED2, LED3, LED4);
+
+//websocket: configuration with sub-network = demo and mbed_id = mbed_led
+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() {
+
+ EthernetInterface eth;
+ eth.init(); //Use DHCP
+ eth.connect();
+ printf("IP Address is %s\n\r", eth.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-rtos.lib Fri Aug 24 14:57:31 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Aug 24 14:57:31 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file
Samuel Mokrani