MQTT Modbus to Thingsboard

Hello,

Is it possible to modify the transmission format in MQTT Modbus Gateway on a RUT956? For example, a script that reads data from MQTT like:

{ "Device": "RUT", "Relay": 1 }

or:

"RUT": { "Relay": 1 }

or:

{ "RUT_Relay": 1 }

…and then the script would translate it depending on what’s set in the Modbus client or into something like:

{
  "cookie": 65432,
  "type": 0,
  "host": "192.168.1.1",
  "port": 502,
  "timeout": 1,
  "server_id": 1,
  "function": 6,
  "register_number": 203,
  "value": 0
}

I have no idea where to start or any example to go by. I’m trying to fully integrate it into ThingsBoard and it seems very complicated, even though it’s an extremely good device from many points of view. But I’m forced to give up on it because I can’t manage to write Modbus registers over MQTT in a simpler, scalable way. It seems bad idea to me to use a Raspberry Pi just to act as a gateway for ThingsBoard.

Thanks for help!
Have a nice day,

Hello,

Could you please clarify your intended workflow a bit further, especially regarding why you need to read data from MQTT? Is the goal to retrieve the current relay state via MQTT messages and then act upon it?

If so, this could actually be handled locally using a simple script. For example, you can query the relay state via CLI with:

ubus call ioman.relay.relay0 status

and then, based on the returned value, publish an MQTT message using mosquitto_pub in your preferred JSON structure.

Additionally, here are some relevant topics that might be helpful or bring insights:

If this is not the intended setup you’re looking for, could you clarify it a bit more? Thank you.

Best regards,