8 years, 7 months ago.

mbed RPC affixes "run" to end of every output

I'm using RPCFunction to define a custom function to fetch temperature from a sensor then output the variable. However, the output includes the word "run", which I'm not adding and can't seem to prevent. Sorry if this is a noob question, but is this inherent with all RPC calls? I was hoping to format the output as standard JSON, but that's never going to work if it constantly adds the word run to everything. I understand when accessing the rpc/temperature/ URL it's going to output "run" and "delete" as those are endpoints available, but surely when accessing the run endpoint it shouldn't be adding this?

void get_temperature(Arguments * input, Reply * output){
    int error = 0;
    float c = 0.0f;
    char arg[10];
    error = sensor.readData();
    if (0 == error) {
        c   = sensor.ReadTemperature(CELCIUS);
        sprintf(arg,"%4.2f",c);
        output->putData(arg);
    }
}

A sample output when accessing http://192.168.1.232/rpc/temperature/run is

22.00 run

So - how do I prevent the "run" from being affixed on the end? Is that normal, or is there something wrong with my mbed-rpc interface library that I'm using? Thanks!

1 Answer

8 years, 6 months ago.

Hi James,

I've also encountered this error. Not sure if it helps but this has only started occuring to me since I updated to the latest mbed-rpc library.

In my case when calling the following code using:

/PING/run 1

I receive:

Connected! run

void        Ping(Arguments * in, Reply * out);      RPCFunction RPC_Ping(&Ping, "PING");

...

void Ping(Arguments * in, Reply * out)
{
    COMM = 1;
    wait_ms(500);
    ACTV = 1;
    wait_ms(500);
    SWP = 1;
    wait_ms(500);
    SWTCH = 1;
    wait_ms(1000);
    COMM = ACTV = SWP = SWTCH = 0;
    out->putData("Connected!");
}

I've messed around a bit and it seems that this "run" string is being inserted into the outbuf during:

RPC::call(buf, outbuf)

Any thoughts?

Edit: Solution in comments.

To be honest, I gave up on RPC and decided to use MQTT instead. The implementation seems to be a lot more solid, and works with OpenHAB too. https://developer.mbed.org/users/jamesabruce/code/MQTTw7500/

The only problem seems to be it stopped broadcasting after a few days. Probably a memory leak or something, but I'm not smart enough to track it down. Still, a lot more effective than messing around with RPC. ;)

posted by James Bruce 09 Oct 2015

Posting this here then incase anyone else encounters the error:

A simple fix seems to be deleteing the mbed-rpc library from your program and then reimporting it. I know the repository was superceeded a few times so might have to be an issue with that? In either case all working fine now, no "run" at the end of the replies :D

posted by Sam Hefford 12 Oct 2015