RPC over HTTP example.
Dependencies: EthernetInterface HTTPServer mbed-rpc mbed-rtos mbed
Fork of RPC_HTTP by
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".
HTTP_RPC.cpp
- Committer:
- sarahmarshy
- Date:
- 2015-06-15
- Revision:
- 5:5322cbfd7c01
- Parent:
- 4:a1b6651dd2ae
File content as of revision 5:5322cbfd7c01:
/* 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" RpcDigitalOut led1(LED1,"led1"); EthernetInterface eth; HTTPServer svr; int main() { //Turn the LEDs off led1.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, ð); printf("Listening...\n"); Timer tm; tm.start(); //Listen indefinitely while(true) { svr.poll(); if(tm.read()>.5) { tm.start(); } } }