How can I implement high-frequency Modbus TCP polling with delta-based MQTT reporting on RUT241?

I am using a RUT241 and need to build a Modbus-to-MQTT data bridge.
Before implementing anything myself, I want to understand whether this can be done with the built-in RUTOS features, and if not, how I should implement it manually.

My requirements:

  1. The router must poll several Modbus TCP registers from a PLC every 100 ms.

  2. Each polling cycle should compare the values to the previous cycle.

  3. Only the changed registers should be sent to my MQTT broker (delta reporting).

  4. The router must also receive MQTT messages and write the new values back to the PLC via Modbus TCP.

  5. Both connections must remain persistent:

    • Modbus TCP should keep a stable long-lived session (no reconnect on each cycle).

    • MQTT should maintain a keepalive connection without reconnecting.


My questions:

1. Is it possible to achieve this using only the built-in RUTOS functionality?
For example using:

  • Modbus TCP Master

  • Data to Server rules

  • MQTT Publisher

  • Event/trigger functions

  • Any existing delta-publish mechanisms

If yes, what is the recommended configuration?

2. If the built-in tools cannot meet the requirements (100 ms interval, persistent Modbus TCP, MQTT delta publishing):
What is the officially supported way to implement this manually?

  • Is a custom script (shell, Python, Lua, etc.) the correct approach?

  • Are there restrictions regarding high-frequency Modbus polling from user scripts?

  • Is it safe to maintain a persistent Modbus TCP session from a script?

  • Which Modbus and MQTT tools/libraries already exist on RUT241 and are recommended for custom use?

3. If a script is the right solution:
Where should it be placed and how should it be executed (init.d service, custom daemon, etc.) so that it runs reliably on startup?


Any official guidance or best practices for implementing this type of high-frequency Modbus-to-MQTT delta bridge on the RUT241 would be greatly appreciated.
Thank you.

Hello,

This sounds a bit overkill, as our WebUI has a limitation that would allow you to set the rate as low as 1000 ms, or 1 second. You may be able to workaround this limitation through the use of a custom script, but I doubt that the device will be able to handle it properly; there will most likely be some skipping of data/failures.

These two will definitely require a custom script, since we don’t have these options available within the WebUI.

Need confirmation from the R&D regarding these, but I believe that prolonging the session would also require a custom script to be in place, same goes for writing values to the PLC, unless you could try setting up Data to server, depending on the setup.

Looks to be 50/50 - some of these are definitely achievable without, but others definitely require a custom script to be in place. Regarding what to use - you’ve already mentioned those options it looks like.

Yes to the custom script (as for what to use - choice is fully yours, but Python seems to be a pretty popular choice amongst users). Just in case - there’s a package you can install for python under the System → Package Manager section. The full downloadable package list can be found here: https://wiki.teltonika-networks.com/view/RUT241_Package_Downloads

Regarding custom packages, you may be able to install those too, but 100% compatibility is not guaranteed as we don’t officially support them.

Script should be placed in the /etc/rc.local file: RUT241 Custom Scripts - Teltonika Networks Wiki

As custom scripts are out of our, Teltonika Support technical scope, I’m unable to provide you with any examples of how your scripts should look like, or provide advice on how they should be made. You can opt for tools such as ChatGPT, or Stackoverflow to get this set up. Perhaps other users from these forums could help you out as well.

Regards,
M.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.