TRB140 modbus client and MQTT gateway to Thingsboard

Dear Teltonika team,

I’m back with another issue going one step forward…
Here is a reminder of my topology :

Siemens Logo! (modbus server) ↔ TRB140 (modbus client and MQTT gateway) ↔ Thingsboard

As far as data to server is concerned, everything is fine, I’m able to read modbus registers, and send the data for visualization using data to server and custom payload. Right.
But for the other direction, set values in Logo! register by sending MQTT message from Thingsboard, I cannot manage to find the good way. I’m using “shared attributes” updates on the platform, but have no idea how to transfer it via MQTT to the TRB140. Server-side RPC method (which is not quite clear for me…), use rule nodes with custom script to convert JSON-type (such as “parameter1” : value) to the payload format " 0 <IP_TYPE> <SERVER_ID> <MODBUS_FUNCTION> <FIRST_REGISTER> <REGISTER_COUNT/VALUES>"
Which one is the good method?

Any help would be much appreciated…

Hello,

For this one, the simplest thing you could use is the ‘MQTT Modbus Gateway’. Basically, the router will subscribe to a ‘request’ topic where the Thingsboard will publish data to. This request will then be translated to Modbus TCP request which will be forwarded to the Modbus TCP Slave (Server).

 0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SERVER_ID> <MODBUS_FUNCTION> <FIRST_REGISTER> <REGISTER_COUNT/VALUES>

Here’s the format in which the MQTT Client will use to send MQTT data to the gateway.

Example:
If I want to change some modbus params in the Modbus TCP Slave (Server) I will send a data like this:

0 65432 0 192.168.1.1 502 5 1 6 328 1

Explanation:
65432 - cookie
0 - 0 means IPv4
192.168.1.1 - IP of the Modbus TCP Server (Slave)
502 - Port
5 - Timeout
1 - Modbus TCP Server ID
6 - Set single holding register based on below:

image


328 - Register number
1 - The value which I want to change into.

More information can be found here - TRB140 Modbus - Teltonika Networks Wiki

Hope this helps if this is the one you were looking for on your requirements.

Best regards,
Robert

Dear @rob_dj ,

Thank you for your answer.
MQTT Modbus gateway is already the functionality that I’m using, I guess I’m on the right path. As far as uplink communication is concerned, everything is working properly. I’m able to read register values and send them with data to server functionality to thingsboard.
On the other way round, once a “shared attrribute” (to which the TRB can subscribe still using the “request” topic of the Modbus gateway) is updated on thingsboard using a widget, I’m able to transform the attribute update using a script and create the right message with the form 0 <IP_TYPE> <SERVER_ID> <MODBUS_FUNCTION> <FIRST_REGISTER> <REGISTER_COUNT/VALUES>. Problem is that Thingsboard uses JSON, and payload has the form {“message” : “0 65432 0 192.168.1.1 502 5 1 6 328 1”}, and not only “0 65432 0 192.168.1.1 502 5 1 6 328 1”. Is there any way for the gateway to deal with JSON on the downlink way ? (and only use the “data” corresponding to the “message”)

This topic was automatically closed after 15 days. New replies are no longer allowed.