RPC over HTTP and custom function

16 May 2011

I know how to turn a LED ON using a RPC command over HTTP. For example http://<your_ip_address>/rpc/led4/write 1.

But I would like to toggle an output pin (100us ON, 200us OFF, 100us ON and so on) by using a RPC command.

How do I do this?

17 May 2011

I found the information myself. http://mbed.org/cookbook/RPC-Interface-Library Next time I will read or search better, before posting

17 May 2011

Hi Jasper

The information you've found is a good way of making custom funtionality over RPC. However, looking at what you want to achieve, an output pin toggling continuously (if I've understood what you're trying to acheive correctly) then you might find it easiest to use PwmOut which works with RPC in the same way as the DigitalOuts/LEDs do. You can set the period and pulsewidth using RPC without needing to define a custom function. This might give you the type of output you are looking for quickly.

eg: http://<your_ip_address>/rpc/led4/period_us 300

http://<your_ip_address>/rpc/led4/pulsewidth_us 100

Where you've defined led4 as an PwmOut rather then a DigitalOut. You can use PWM out on pins 21-26 and the LEDs

Michael

17 May 2011

Hi Michael.

I want to open the garage door with a 433Mhz RF transmitter (like this http://www.sparkfun.com/products/8946). I will connect one digital pin from the mbed to the transmitter. All I need to do is toggle that pin according to a certain pattern. In this case that's not so repetitive that I can use a PWM output. The example in the RPC Interface library is exactly what I need. I will call a RPCfunction that toggles the output pin.

http://<your_ip_address>/rpc/garagedoor/open

Jasper

17 May 2011

Ok I have the HTTP server and RPC handler working and I can turn on a LED. I have imported the RPCInterface libary into the program. However I cannot get RPCFunction example code to run

//Create a function of the required format
void foo(char * input, char * output);
//Attach it to an RPC object
RPCFunction rpc_foo(&foo, "foo");

void foo(char * input, char * output){
   int x,y;
   sscanf(input, "%i, %i", &x, &y);

   //Do something here......

   sprintf(ouput, "%i, %i", x, y );
}

The compiler complaints: Identifier "RPCFunction" is undefined (E20) in the line containing "RPCFunction rpc_foo(&foo, "foo");"

The compiler also complaints about: "Expected a ")" (E18) in the same line

The compiler complaints about: "Identifier "ouput" is undefined (E20)

I can imagine it complaints about "ouput" without the t. However when I add #include "RPCInterface.h" to the code the first two errors disapear and the new error is:

"Cannot open source input file "RPCInterface.h": No such file or directory (E5)

Can you create a working RPCfunction example that flashes a LED three times and post it to the cookbook? And also the RPC command?

17 May 2011

Hi

Import libraryRPCInterface

Library to provide a mechanism to make it easier to add RPC to custom code by using RPCFunction and RPCVariable objects. Also includes a class to receive and process RPC over serial.

If you look through the library then you see there is no file "RPCInterface.h" in the library hence you get that error. To use RPCFunctions, you need to include "RPCFunction.h" or to use RPCVariables "RPCVariable.h"

The header files correspond to each classes name not the library name, thats just the name they are grouped and published under.

Michael

17 May 2011

Hi Michael, Thanks. I found out that its is important to correctly write uppercase and lower case.

  1. include "RPCfunction.h" doesn't work
  1. include "RPCFunction.h" does

Jasper

17 May 2011

Finally my code is working

when I call http://<your_ip>/rpc/foo/run

this function is called

void foo(char * input, char * output){
   int x,y;
   sscanf(input, "%i, %i", &x, &y);

   //Do something here......
   led2 = 1;
   led3=1;
   led4=1;

   sprintf(output, "%i, %i", x, y );
}

and the LEDs go on!

Thanks Michael!

Jasper

18 May 2011

Hi Michael, I just want to inform that I have my project functionally working. Now I can call a function through RPC over http. The function toggles a pin that is connected to a 433Mhz wireless data transmitter. I can now open the garage door through a link!! Michael+1