Double RPC mqtt messages?

Am I seeing double?
When I publish a RPC message via MQTT I see two messages in system log , I don’t see the same issue when I send via http (curl)
curl “http://192.168.0.103/rpc/relay” -d “{“name”:“RELAY1”, “cmd”: “SWITCH”}”
{“msg”:“ok”,“status”:“true”}

eg
mosquitto_pub -h mybroker -t esp32_8AD88C/rpc -m '{“method”:“relay”,“args”:{“name”:“TEST1”}}'

system log:

 [Sep 19 13:07:41.718] mg_rpc.c:310            relay via MQTT 
 [Sep 19 13:07:41.718] args: {"name":"TEST1"} 
 [Sep 19 13:07:41.718] mg_rpc.c:310            relay via MQTT 
 [Sep 19 13:07:41.718] args: {"name":"TEST1"} 

mjs : program …

// Load Mongoose OS API
load('api_timer.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_net.js');
load('api_config.js');
load('api_rpc.js');


RPC.addHandler('relay', function(args) {

   let rc=true;
   print("args:",JSON.stringify(args));
 
  return {"status": rc  };
});


// check if MQTT connection establised and sent init
MQTT.setEventHandler(function(conn, ev, edata) 	{
	//check if connection to MQTT established
		if(ev === MQTT.EV_CONNACK)	{
		  print('MQTT Connected');
	  
		}
	}, null);

also sending issue?? I don’t see any response via the “src” channel.

eg
mosquitto_pub -h mythbox -t esp32_8AD88C/rpc -m ‘{“src”:“out-topic”,“method”:“relay”,“args”:{“name”:“RELAY1”,“cmd”:“SWITCH”}}’

should I see out on mqtt channel: out-topic/rpc ??

You are missing the ‘id’ key. According to my understanding, there won’t be a response if there is no command id.
The docs show the use of ‘params’ instead of ‘args’. I don’t know if this will affect operation, there is this comment in the sources: /* Note: at present we allow both args and params, but args is deprecated. */
When I wrote this article (in Spanish), everything worked fine.
Which version are you using ?

1 Like

working now… documentation wasn’t quiet clear on the meaning of those extra values and it appears it hasn’t been updated in a while.
thanks

Question version?
I think its Mongoose 6.18, LwIP 2.1.3 according to the boot messages is there another way to tell?

How do I compile with latest version?

Latest version of what?

The latest release version of mos is 2.19.1.
If you want to use the latest versions of Mongoose OS and libraries, switch to mos latest:

mos update latest

just adding this for future referance
change the following config
"rpc.mqtt.sub_wc", false

or
mos config-set rpc.mqtt.sub_wc=false

Perfect @scaprile! Example of Config.Get and Config.Set:

RPC Config:

rpc: {
...
"mqtt": {
    "enable": true,
    "pub_topic": "from/N9I0FSHV/response/rpc",
    "qos": 0,
    "sub_topic": "to/N9I0FSHV/request/rpc",
    "sub_wc": false
  },
...
}

Request CONFIG.GET on topic to/N9I0FSHV/request/rpc:

{
"id":321, 
"src":"Config.Get.Values", 
"method":"Config.Get", 
"params":{"key":"device.model", "level":9}
}

Response on topic from/N9I0FSHV/response/rpc:

{"id":321,"src":"N9I0FSHV", "dst":"Config.Get.Values", "result":"X1201"}

Request CONFIG.SET on topic to/N9I0FSHV/request/rpc:

{
"id":123, 
"src":"Config.Get.Values", 
"method":"Config.Set", 
"params":{"config":{"device":{"model": "X120"}}, "level": 9, "save":true, "try_once":false, "reboot":true}
}

Response on topic from/N9I0FSHV/response/rpc:

{"id":123, "src":"N9I0FSHV", "dst":"Config.Get.Values", "result":{"saved": true}}

Unfortunatelly the documentation is not so clear about it. Mining the code you can find out something further.