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".

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Mon Jun 15 16:29:24 2015 +0000
Parent:
1:71b64a776133
Child:
3:6cfcccfe3995
Commit message:
Working example of RPC over HTTP.

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServerExample.cpp Show diff for this revision Revisions of this file
HTTP_RPC.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rpc.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Mon Jun 15 16:29:24 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sarahmarshy/code/EthernetInterface/#be165aa9a49b
--- a/EthernetNetIf.lib	Thu Sep 09 13:47:59 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- a/HTTPServer.lib	Thu Sep 09 13:47:59 2010 +0000
+++ b/HTTPServer.lib	Mon Jun 15 16:29:24 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
+http://developer.mbed.org/users/sarahmarshy/code/HTTPServer/#c690fb2de477
--- a/HTTPServerExample.cpp	Thu Sep 09 13:47:59 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*
-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 "EthernetNetIf.h"
-#include "HTTPServer.h"
-
-DigitalOut led1(LED1, "led1");
-DigitalOut led2(LED2, "led2");
-DigitalOut led3(LED3, "led3");
-DigitalOut led4(LED4, "led4");
-
-LocalFileSystem fs("webfs");
-
-EthernetNetIf eth;  
-HTTPServer svr;
-
-int main() {
-    Base::add_rpc_class<AnalogIn>();
-    Base::add_rpc_class<AnalogOut>();
-    Base::add_rpc_class<DigitalIn>();
-    Base::add_rpc_class<DigitalOut>();
-    Base::add_rpc_class<DigitalInOut>();
-    Base::add_rpc_class<PwmOut>();
-    Base::add_rpc_class<Timer>();
-    Base::add_rpc_class<BusOut>();
-    Base::add_rpc_class<BusIn>();
-    Base::add_rpc_class<BusInOut>();
-    Base::add_rpc_class<Serial>();
-
-  printf("Setting up...\n");
-  EthernetErr ethErr = eth.setup();
-  if(ethErr)
-  {
-    printf("Error %d in setup.\n", ethErr);
-    return -1;
-  }
-  printf("Setup OK\n");
-  
-  FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
-  FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
-  
-  svr.addHandler<SimpleHandler>("/hello");
-  svr.addHandler<RPCHandler>("/rpc");
-  svr.addHandler<FSHandler>("/files");
-  svr.addHandler<FSHandler>("/"); //Default handler
-  //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
-  
-  svr.bind(80);
-  
-  printf("Listening...\n");
-    
-  Timer tm;
-  tm.start();
-  //Listen indefinitely
-  while(true)
-  {
-    Net::poll();
-    if(tm.read()>.5)
-    {
-      led1=!led1; //Show that we are alive
-      tm.start();
-    }
-  }
-  
-  return 0;
-
-}
--- /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();
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rpc.lib	Mon Jun 15 16:29:24 2015 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/mbed/code/mbed-rpc/#d8113058854e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Jun 15 16:29:24 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#ed4ff3bea947
--- a/mbed.bld	Thu Sep 09 13:47:59 2010 +0000
+++ b/mbed.bld	Mon Jun 15 16:29:24 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file