RPC hello world over Ethernet

Dependencies:   EthernetInterface MbedJSONRpc MbedJSONValue WebSocketClient mbed-rtos mbed

Files at this revision

API Documentation at this revision

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

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
MbedJSONRpc.lib Show annotated file Show diff for this revision Revisions of this file
MbedJSONValue.lib Show annotated file Show diff for this revision Revisions of this file
WebSocketClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6538aa30a040 EthernetInterface.lib
--- /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
diff -r 000000000000 -r 6538aa30a040 MbedJSONRpc.lib
--- /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
diff -r 000000000000 -r 6538aa30a040 MbedJSONValue.lib
--- /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
diff -r 000000000000 -r 6538aa30a040 WebSocketClient.lib
--- /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
diff -r 000000000000 -r 6538aa30a040 main.cpp
--- /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
diff -r 000000000000 -r 6538aa30a040 mbed-rtos.lib
--- /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
diff -r 000000000000 -r 6538aa30a040 mbed.bld
--- /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