RPC.call(RPC.LOCAL) sends method call to MQTT broker

  1. My goal is to get the output from Sys.GetInfo for further work within the code
  2. My actions were to follow the example from the documentation and here:
Event.on(Event.CLOUD_CONNECTED, function () {
  RPC.call(device_id, 'Sys.GetInfo', null, function (resp, err_code, err_msg, ud) {
    if (err_code !== 0) {
      Log.debug("Error: (" + JSON.stringify(err_code) + ') ' + err_msg);
    } else {
      Log.debug('Result: ' + JSON.stringify(resp));
    }
  }, null);
}, null);
  1. The result I see is that I get a message with the content {"src":"my_device_id","dst":"my_device_id","id":4069,"method":"Sys.GetInfo","params":} at the MQTT broker in the response topic.
  2. My expectation & question is that I would get the output of the response from the RPC.LOCAL call within the callback. I suspect, that RPC-MQTT redirects the RPC.call method directly to the MQTT broker.

I would really love to understand how I can redirect the output into the callback function.

Thanks a lot for your support.

Hey @nlsrchtr , I’m not sure I understand what you’re asking.

It sounds like you’re saying you want to intercept the call to Sys.GetInfo and do some extra stuff in that callback function. I’m not 100% sure but sounds to me like that wouldn’t be possible.

Not sure of your intention, but seems like it would be easier to replicate the RPC call in your own custom function and call that.

Hi @klimbot,

thanks for getting back to me and sorry, when my question was not clear enough. The problem is, that every call of:

sends the response to the connected MQTT broker. So the expected and correct answer can be found in the MQTT topic, but this was not my intention. I need the response of “Sys.GetInfo” within my code to work with the values further.

That’s why I tried with RPC.call(RPC.LOCAL) as well, but there was not change at all.

Any idea?

Thanks for your support.

Regards,

Do not try, just read the docs and do what they say.

Hi @scaprile,

thanks for getting back to me and also for the pointer to the documentation.

This is the code, I’m running:

Event.on(Event.CLOUD_CONNECTED, function () {
  Log.debug("Connected to MQTT...");

  RPC.call(RPC.LOCAL, 'Sys.GetInfo', null, function (resp, ud) {
    Log.debug('Response:', JSON.stringify(resp));
    Log.debug('MAC address:', resp.mac);
  }, null);
}, null);

As I wrote in my initial message, the call from the documentation is not giving me the output, but is trying sending a message via MQTT:

[Dec  8 14:34:21.398] init.js:147             Connected to MQTT...
[Dec  8 14:34:21.413] mg_rpc.c:246            'RPC.LOCAL' -> 0x3ffd14e8
[Dec  8 14:34:21.417] mg_rpc.c:698            QUEUED FRAME (71): {"src":"sbcE36728","dst":"RPC.LOCAL","id":15920,"method":"Sys.GetInfo"}
[Dec  8 14:34:21.428] mgos_event.c:135        ev MOS4 triggered 2 handlers
[Dec  8 14:34:21.431] mgos_mqtt_conn.c:168    MQTT0 sub xyz/unprovisioned/sbcE36728/rpc @ 1
[Dec  8 14:34:21.441] mongoose.c:3007         0x3ffd7758 udp://162.159.200.123:123
[Dec  8 14:34:21.447] mongoose.c:3022         0x3ffd7758 udp://162.159.200.123:123 -> 0
[Dec  8 14:34:21.453] mgos_sntp.c:53          SNTP sent query to 162.159.200.123
[Dec  8 14:34:21.469] mgos_sntp.c:64          SNTP reply from 162.159.200.123: time 1765200862.361055, local 43.850190, delta 1765200818.510865
[Dec  8 14:34:21.478] mgos_event.c:135        ev MOS3 triggered 4 handlers
[Dec  8 14:34:21.485] mgos_mqtt_conn.c:179    MQTT0 event: 209
[Dec  8 14:34:21.488] mg_rpc.c:499            0x3ffd14e8 CHAN OPEN (MQTT)
[Dec  8 14:34:21.494] mgos_event.c:135        ev RPC0 triggered 0 handlers
[Dec  8 14:34:21.500] mgos_rpc_channel_mq:153 Published [{"src":"sbcE36728","dst":"RPC.LOCAL","id":15920,"method":"Sys.GetInfo"}] to topic [xyz/unprovisioned/RPC.LOCAL/response]
[Dec  8 14:34:21.514] mg_rpc.c:678            0x3ffd14e8 SEND FRAME (71): {"src":"sbcE36728","dst":"RPC.LOCAL","id":15920,"method":"Sys.GetInfo"} -> 1

The delivery of the message to the topic xyz/unprovisioned/RPC.LOCAL/response is failing, because topic names with “.” are not allowed in MQTT. Therefor I was trying to use the device_id, which works and I get the following message into the topic xyz/unprovisioned/sbcE36728/response:

{"src":"sbcE36728","dst":"sbcE36728","id":18405,"method":"Sys.GetInfo"}

and there is no logging output at all given, related the code, like the “Mac address” or something else.

So I was under the impression, that the RPC-MQTT module seems to redirect all calls to MQTT somehow.

Do you have any other suggestion or idea on how I could report the IP address of the device as a message to the MQTT broker? Since this would be really helpful.

Regards,

OK, that’s weird.
Since you were kind enough to tell what you wanted to do, not just how you failed at how you thought that should be done, let’s see how to work on your actual problem, instead.

Here:

// Monitor network connectivity.
Event.addGroupHandler(Net.EVENT_GRP, function(ev, evdata, arg) {
  let evs = '???';
  if (ev === Net.STATUS_DISCONNECTED) {
    evs = 'DISCONNECTED';
  } else if (ev === Net.STATUS_CONNECTING) {
    evs = 'CONNECTING';
  } else if (ev === Net.STATUS_CONNECTED) {
    evs = 'CONNECTED';
  } else if (ev === Net.STATUS_GOT_IP) {
    evs = 'GOT_IP';
  }
  print('== Net event:', ev, evs);
}, null);

evdata already has what you want: mongoose-os/src/mgos_net.c at aa4a2491a49381af2a427cbb722ff3980b3a072b · cesanta/mongoose-os · GitHub

AND, your function is already getting the info you want, only that you are ignoring parameters being passed to it: Mongoose OS Documentation