Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

invalid character '"' after object key:value pair

I am implementing an RPC, I followed the provided example in here and I had NO issues.
Then I tried to implement my own, so I changed %lf to %Q to accept a string and changed the double to be a pointer to a character to store the provided string but it didn't work well.
I always get this error when calling it mos call Wifi.Connect '{"ssid": "Wifif", "pass":"123456"}'

E0203 03:22:07.742949   10359 stream.go:227] [streamConnectionCodec to /dev/cu.SLAB_USBtoUART]: failed to parse frame: "{\"id\":1377510388619,\"src\":\"esp8266_0C8062\",\"dst\":\"mos\",\"result\":\"all\" \"good\"}c4d2e34b" invalid character '"' after object key:value pair
Error: context deadline exceeded
/private/tmp/mos-20190124-47401-1cjy3pq/mos-tool-e5d271263e971b1d6414d5885f780ddb48b2458b/src/ call failed
exit status 1

RPC Implementation:

#include "mgos_rpc.h"
#include "common/cs_dbg.h"
#include "common/json_utils.h"
#include "common/platform.h"
#include "mgos_app.h"
#include "mgos_utils.h"

static void wifi_connect_rpc_handler(struct mg_rpc_request_info *ri, void *cb_arg,
                                     struct mg_rpc_frame_info *fi, struct mg_str args)
    char *ssid = NULL;
    char *pass = NULL;
    json_scanf(args.p, args.len, ri->args_fmt, &ssid, &pass);

    if (ssid == NULL)
        mg_rpc_send_errorf(ri, -1, "Bad request.");
        mg_rpc_send_responsef(ri, "All good");


enum mgos_app_init_result mgos_app_init(void)
    mg_rpc_add_handler(mgos_rpc_get_global(), "Wifi.Connect", "{ssid: %Q, pass: %Q}", wifi_connect_rpc_handler, NULL);


  • nliviunliviu Romania
    edited February 3

    The result is an invalid key:value string: \"result\":\"all\" \"good\"

    mg_rpc_send_responsef(ri, "%Q", "All good"); will send the correct response:

    SEND FRAME (73): {"id":1747337944676,"src":"esp32_0511F4","dst":"mos","result":"All good"} -> 1

    LE. pass and ssid should be freed if they are not NULL.

    Thanked by 1ahmed_shaalan
  • Thanks so much. it worked :) @nliviu

Sign In or Register to comment.