Using mg_rpc_send_responsef() to send variable with response

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:

  1. Goes offline from mDash
  2. Returns some message like “device offline”
  3. 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");

Can’t reproduce on ubuntu, esp8266, esp32 building for mos latest, 2.20.0 and 2.19.1.
Can you provide a simple application to reproduce your issue?

The code snippet is now working for me as well. I probably got confused with my testing and what was/wasn’t working when I tried to cut down the example, sorry about that.

After some testing, what was actually causing the failure was this:

mg_rpc_send_responsef(ri, "feedback: %lf", feedback);

In trying to pin down whats causing it, I’ve had a look at some similar working RPC functions and realised that my error was to do with formatting of the response - I’m guessing it was something to do with valid JSON maybe?

This now works:

mg_rpc_send_responsef(ri, "{feedback: %lf}", feedback);

Not sure if I missed this in the documentation somewhere.