Integration MQTT Modbus gateway with ThingsBoard RPC Call Requests

Hi, I am using TRB140. I am trying to execute RPC call request from thingsboard but the commands do not work because RPC Call Requests from Thingsboard are sent with a specific JSON structure. For example (from the official documentation):

{
   "method": "setGPIO",
   "params": {
     "pin": 4,
     "value": 1
   },
  "timeout": 30000
}

You can find the documentation of thingsboard RPC here:

under the section “Server-side RPC structure“.

As you can see, the message, in this case, what I want the MQTT Modbus gateway to process, is inside the key “params“. Even if in thingsboard I move the content to the root of the JSON before executing the RPC Call Request, ThingsBoard does not send anything that is not expected, so it removes it.

Therefore I have the limitation that thingsboard speaks a language that MQTT modbus gateway cannot understand. What I would need is an option in MQTT modbus gateway where I can specify that the content of “params“ has to be used.

Just one more thing, I found a work around that is not the right thing to do with with thingsboard, but it proves that all the communication works well. From thingsboard, instead of executing an RPC Call Request I send an MQTT message to the MQTT broker from the TRB140, and I make the MQTT modbus gateway to listen to the local MQTT broker, where it has the modbus commad. This works well. But it is not the right apporach, because thingboard need a response in order to know that the RPC command works. By the way, the RPC call request makes a connection, because I see it is able to confirm the response from the TRB140, and that is great news. The problem is that the command sent, the MQTT Modbus Gateway is not able to interpret because of the JSON structure that cannot be changed in thingsboard when using RPC Call Request.

Thank you in advance

Greetings,

You should be able to achieve this functionality by implementing a custom script on the device. Since script development falls outside the scope of our technical support, I’m unfortunately not able to assist with creating the script itself. However, you can find useful script examples here: User Scripts examples - Teltonika Networks Wiki

As you mentioned that you have setup a local MQTT broker, the script logic could follow this approach:

The script would subscribe to the ThingsBoard RPC request topic. When a message is received, it would parse the JSON payload, extract the request ID from the topic, and retrieve the content inside the params field. It would then reformat this data and publish it to the appropriate local MQTT topic used by the MQTT Modbus Gateway.

Afterward, the script would listen for the response from the MQTT Modbus Gateway, wrap that response into the required JSON structure, and publish it back to ThingsBoard using the corresponding RPC response topic.

Best Regards,
Justinas

Great, I will give it a try.

Probably you have many functionalities to implement in the RutOS, but if one of them could be to be able to give some basic instructions to the MQTT Modbus Gateway of how to interpret the message it would be useful. For example, specify which key of the JSON contains the message. That way I would not need to deploy scripts in all the devices and maintain them, which is always a pain.

For the moment I will go for the script.

Thank you very much for your quick response. Such a great service!