RPC over HTTP example.

Dependencies:   EthernetInterface HTTPServer mbed-rpc mbed-rtos mbed

Fork of RPC_HTTP by Michael Walker

This is a working example of using RPC over HTTP. This uses an ethernet connection. The program attaches an RPC handler to LED1. You can use a client program to send commands to this LED, addressing it as "led1".

Revision:
2:33d3bcad6a90
Child:
3:6cfcccfe3995
diff -r 71b64a776133 -r 33d3bcad6a90 HTTP_RPC.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTP_RPC.cpp	Mon Jun 15 16:29:24 2015 +0000
@@ -0,0 +1,74 @@
+/*
+Copyright (c) 2010 ARM Ltd
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPServer.h"
+#include "mbed_rpc.h"
+
+DigitalOut led1(LED1);
+RpcDigitalOut led2(LED2,"led2");
+RpcDigitalOut led3(LED3,"led3");
+RpcDigitalOut led4(LED4, "led4");
+
+
+EthernetInterface eth;  
+HTTPServer svr;
+
+int main() {
+  //Turn the LEDs off
+  led1.write(1);
+  led2.write(1);
+  led3.write(1);
+  led4.write(1);
+  
+  RPC::add_rpc_class<RpcDigitalOut>();
+
+  printf("Setting up...\n");
+  eth.init();
+  int ethErr = eth.connect();
+  if(ethErr < 0)
+  {
+    printf("Error %d in setup.\n", ethErr);
+    return -1;
+  }
+  
+  svr.addHandler<HTTPRpcRequestHandler>("/rpc");
+  
+  //attach server to port 80
+  svr.start(80, &eth);
+  
+  printf("Listening...\n");
+    
+  Timer tm;
+  tm.start();
+  //Listen indefinitely
+  while(true)
+  {
+    svr.poll();
+    if(tm.read()>.5)
+    {
+      //led1=!led1; //Show that we are alive
+      tm.start();
+    }
+  }
+
+}