Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface HTTPD mbed-rtos mbed mbed-rpc
Revision 1:2971dd3e5168, committed 2013-11-13
- Comitter:
- okini3939
- Date:
- Wed Nov 13 06:59:58 2013 +0000
- Parent:
- 0:c4a353ed707d
- Commit message:
- RPC support
Changed in this revision
| main.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 |
--- a/main.cpp Wed Nov 13 02:00:05 2013 +0000
+++ b/main.cpp Wed Nov 13 06:59:58 2013 +0000
@@ -1,6 +1,7 @@
#include "mbed.h"
#include "rtos.h"
#include "EthernetInterface.h"
+#include "mbed_rpc.h"
#include "HTTPD.h"
EthernetInterface *eth;
@@ -41,20 +42,39 @@
httpd->sendWebsocket(id, buf, i);
}
+void callback_rpc (int id) {
+ char buf[40], outbuf[40];
+
+ strcpy(buf, "/");
+ httpd->urldecode(httpd->getFilename(id), &buf[1], sizeof(buf) - 2);
+ RPC::call(buf, outbuf);
+
+ printf("RPC id %d '%s' '%s'\r\n", id, buf, outbuf);
+ httpd->send(id, outbuf, strlen(outbuf), "Content-Type: text/plain\r\n");
+}
+
int main () {
pc.baud(115200);
printf("HTTP Server...\r\n");
eth = new EthernetInterface;
- eth->init(); //Use DHCP
-// eth->init("192.168.1.2", "255.255.255.0", "192.168.1.1");
+// eth->init(); //Use DHCP
+ eth->init("192.168.1.2", "255.255.255.0", "192.168.1.1");
if (eth->connect()) return -1;
printf("IP Address is %s\r\n", eth->getIPAddress());
+// RPC::add_rpc_class<RpcAnalogIn>();
+// RPC::add_rpc_class<RpcAnalogOut>();
+ RPC::add_rpc_class<RpcDigitalIn>();
+ RPC::add_rpc_class<RpcDigitalOut>();
+ RPC::add_rpc_class<RpcDigitalInOut>();
+ RPC::add_rpc_class<RpcPwmOut>();
+
httpd = new HTTPD;
httpd->attach("/cgi-bin/", &callback_cgi);
httpd->attach("/ws/", &callback_ws);
+ httpd->attach("/rpc/", &callback_rpc);
httpd->attach("/", "/local/");
httpd->start(80);
printf("httpd ready\r\n");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rpc.lib Wed Nov 13 06:59:58 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rpc/#4490a0d9cb2a