A quick guide to set up the Teltonika router as a RS485 to TCP Modbus gateway so Modbus TCP master devices within the IP network can access Modbus RS485 slave devices connected to the Teltonika router in a transparent way
If you would like to have an overview about what you can do with Modbus and Teltonika, check our main article HERE
Make sure the Modbus RS485 function is disabled
The RS485 to TCP gateway is a fully transparent gateway that allows any Modbus TCP master device (that being the Teltonika internal Modbus TCP Master driver or a third part Modbus TCP Master device within the network or remote!) to access the RS485 slave devices connected to the Teltonika router.
For this feature to work, it is essential to make sure that the Modbus RS485 serial driver is disabled. In fact the RS485 Modbus Master would collide with the Gateway function and cause network instabilities.
Go to "Services - Modbus" from the top menu, then select the tab "Modbus Serial Master" and the sub-tab "RS485", and make sure any device on the device list is removed, and untick the "Enabled" checkbox
Configure the router as a gateway
Once we made sure the RS485 port is free, we can set up the gateway function.
We need to select from the top menu "Services - RS232/RS485", then the tab "RS485"
And here is a configuration example of the Modbus RS485 to TCP gateway
After enabling it, the first 4 settings are configuring the RS485 network.
The Serial Type is then configured as "Modbus gateway".
Listening IP I tried both "admin" and "0.0.0.0" and they both worked.
Port 502 is the standard Modbus TCP, but it can be changed if need to.
The Slave ID is better to get from TCP, and allow to use any ID between 1 and 124 to open the gateway in full.
How do I get data from RS485 slave devices to a Tridium supervisor using the Modbus TCP protocol
The Teltonika TCP gateway supports 1 socket a time. This means that if you want to read multiple devices connected to the Teltonika RS485 port using a Tridium driver, you shouldn't use the "Modbus TCP Network" driver: this in fact would open a new socket for every device added to the driver, causing an effect where only one device a time would be seen online and all the others would have the socket closed an going offline.
The right driver to use is the "Modbus TCP Gateway": this will allow you to configure the IP address of the gateway (the Teltonika IP address) once, opening only 1 socket in total, and then add as many slave devices within that driver without having any connection problem.
Here is a Link IO RS485 device connected to the Teltonika and being available to a Niagara Supervisor using the Modbus TCP Gateway
How to communicate RS485 slave data on the Teltonika using Modbus TCP and why
With the Gateway function enable on the Teltonika, not only we can use an external device with Modbus TCP Master enable to ready Modbus RS485 slave devices connected to the Teltonika and use it as a gateway. We can also access the slave devices through the Modbus TCP Master driver within the Teltonika itself.
You might wonder why we should do this, when we have a Modbus RS485 Master driver on the Teltonika natively. The reason is simple: if you want to send data to a remote server, like using MQTT for example (see article HERE), the "Modbus Data to Server" function on the Teltonika works only with Modbus TCP devices, so using the Gateway you can bypass this problem and effectively add Modbus RS485 devices through the gateway to the Modbus Data to Server function.
It is really easy to add your devices and points. Check the full article on how to add devices and points HERE. In this part I am going just to focus on a specific point: the device IP to be used has to be the Teltonika IP address (using the 127.0.0.1 localhost or the local network IP, in my example 192.168.80.1)