I’m trying to implement an RPC that returns the set value (same that was set) in the rpc response using mg_rpc_send_responsef()
like I’ve copied from the RPC docs.
The behaviour I’m seeing is that when I try to return the received value as part of the response my device:
- Goes offline from mDash
- Returns some message like “device offline”
- Eventually falls over
Code looks like this:
static void update_prediction_handler(struct mg_rpc_request_info *ri, void *cb_arg,
struct mg_rpc_frame_info *fi, struct mg_str args)
{
(void)cb_arg;
(void)fi;
double feedback = 0.0;
if (json_scanf(args.p, args.len, ri->args_fmt, &feedback) == 1)
{
some_global_value = feedback;
// Respond to the RPC client the success
// Attempting to respond with the value seems to crash everything
mg_rpc_send_responsef(ri, "%.2lf", feedback);
}
else
{
// Respond to the RPC client the failure, and the expected values
mg_rpc_send_errorf(ri, -1, "Bad request. Expected: {\"value\":<double>}");
}
}
If I change the mg_rpc_send_responsef()
to this everything functions as expected, no crashes or causing the device to go offline:
mg_rpc_send_responsef(ri, "success");