Modbus TCP Client configuration example: Difference between revisions
No edit summary |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
=Summary= | <p style="color:red">The information on this page is updated in accordance with the [https://wiki.teltonika-networks.com/view/FW_%26_SDK_Downloads'''00.07.09'''] firmware version .</p> | ||
Modbus TCP | __TOC__ | ||
==Summary== | |||
This article contains instructions on how to configure Modbus TCP functionality on most of the Teltonika Networks devices (with the exception of TAP and TSW series) | |||
==Configuration overview & prerequisites== | |||
Before we begin, let's take a look at the configuration that we are attempting to achieve and the prerequisites that make it possible. | |||
Configuring port forwarding on Teltonika devices is a simple process that involves just a few steps and can easily be replicated across various devices. The number of devices involved will depend on the specific use case, but the setup can be scaled seamlessly. In the example below, we will use the RUTX50 as the Modbus TCP Client and RUT956 as Modbus TCP Server. | |||
[[File:Networking Topology Modbus basic config.png|border|class=tlt-border|]] | |||
[[ | '''Prerequisites''': | ||
* A device from the RUT, RUTX, RUTM, RUTC or TRB series gateway; | |||
* A PC, Laptop, tablet or a smartphone | |||
* Router acting as Modbus TCP Server must have a SIM card with a Public Static or Public Dynamic IP address (more on IP address types '''[[Private and Public IP Addresses|here]]''') to make remote access possible | |||
* (Optional) If the router's SIM card has a Public Dynamic IP address, you may want to additionally configure a '''[[Dynamic DNS]]''' hostname | |||
{{Template:Networking_rutos_manual_basic_advanced_webui_disclaimer | |||
| series = RUTX | |||
}} | |||
=Modbus TCP Server= | |||
Configure Modbus TCP Server device. our slave device to have a 192.168.1.2 internal IP address. This can be done by changing the IP address parameter on Network → WAN page: | |||
==Modbus TCP Server configuration== | |||
Setup router as Modbus TCP Server. It can be done in '''Services → Modbus → Modbus TCP Server '''. Once in the Modbus TCP Server configuration, find the '''Enable''' the instance and '''turn on the Allow remote access'''. Everything else can be left as default or changed based on your needs: | |||
[[File:Modbus TCP server config new.png|border|class=tlt-border]] | |||
Once finished click '''Save & Apply''' to save the configuration. | |||
== | ==Remote access configuration== | ||
If you wish to remotely access the Modbus TCP Server device navigate to the '''System → Administration → Access Control''' tab. Once in the '''Administration-Access Control''', find the '''Enable remote HTTP access''' field and put a check mark next to it: | |||
[[File: | [[File:enable remote access HTTP.png|border|class=tlt-border|]] | ||
'''Note:''' If you have a Public IP address already, you can skip this step. | |||
To set the APN, while in the router's WebUI, navigate to the '''Network → Mobile → General → Interface mob1s1a1 APN configuration''': | |||
[[File:Set APN PF.png|border|class=tlt-border|alt=]] | |||
Once in the '''Interface mob1s1a1 APN configuration''' window, edit your mobile interface, find the '''APN''' field and enter you Internet Service Provider's APN: | |||
# '''Disable the Auto APN option''' | |||
# Choose the correct '''APN''', which gives out a public IP address (for more information about that contact your Internet Service Provider) | |||
[[File:Set APN PF APN selected.png|border|class=tlt-border]] | |||
Additional notes on APN: | |||
* '''NOTE 1''': don't use the exact APN value as seen in the example above as it will not work with your SIM card. APN depends on your Internet Service Provider (ISP), therefore, your ISP should provide you with their APN or, in many case, you can find your ISP's APN with an online search. | |||
* '''NOTE 2''': furthermore, it should be noted that not all SIM cards support this functionality. Static or Dynamic Public IP addresses (obtained through APN) are a paid service and setting any APN value for a SIM card that doesn't support this service will most likely result in losing your data connection. If this is the case, it can be fixed by simply deleting the APN, but it also means that remote access through mobile WAN IP will most likely not work on your SIM card. | |||
* '''NOTE 3''': in some cases the SIM card doesn't require an APN in order to obtain a Public IP address. If that is the case for you, simply check what your router's mobile WAN IP address is - if it's already a Public IP address, then you don't need to set an APN. The easiest way to find what your mobile WAN IP address is to log in to the router's WebUI and check the '''MOB1S1A1''' widget in the '''Overview''' page: | |||
[[File:Where public IP.png|border|class=tlt-border]] | |||
=Modbus TCP Client= | |||
== | ==Modbus TCP Client configuration== | ||
On the Modbus TCP Client device open Services → Modbus → Modbus TCP Client. To create a new instance click on '''Add'''. A new pop-up window should appear: | |||
# '''Enable''' the '''instance''' | |||
# '''Enter''' the '''desired name''' | |||
# '''Server ID''' must match with the previously configured '''Server device ID''' | |||
# Enter the '''mobile WAN IP address of the Modbus TCP Server device''' | |||
# Chose same '''Port as in Server device - 502''' | |||
# Enter '''Period in seconds''', how often requests will be sent to the Server device | |||
[[File:Enable modbus tcp client config.png|border|class=tlt-border]] | |||
==Requesting Modbus data== | |||
For testing, if the functionality is working we can configure a request. A Modbus request is a way of obtaining data from Modbus Server. The Client sends a request to a Server specifying the function code to be performed. The Server then sends the requested data back to the Modbus Client. | |||
Write a name for the request and click the | Scroll down to the '''Request configuration''' section. Write a name for the request and click the '''Add''' button: | ||
[[File: | [[File:Add new request modbus tcp client.png|border|class=tlt-border]] | ||
In this case we are trying to get System temperature (in 0.1 °C) information so configure the next options: | |||
# '''Data type''': 32bit INT, Byte order 1,2,3,4 | |||
# '''Function''': Read holding registers (3) | |||
# '''First register''': 6 | |||
# '''Number of register'''s: 2 | |||
# '''Enble''' brackets if not needed | |||
# '''Enable''' the request | |||
The information about correct Modbus registers usage can be found [[https://wiki.teltonika-networks.com/view/Monitoring_via_Modbus_RUTOS|'''here''']]. | |||
[[File:Add new request modbus tcp test.png|border|class=tlt-border]] | |||
Under the '''Request Configuration''' section there will be another section called '''Request Configuration Testing''' this is where you can test that the parameters that you set work properly. Just select the request that you want to test and click the '''test button''' and you should get an output. | |||
= | [[File:Testing modbus TCP client data.png|border|class=tlt-border]] | ||
=See Also= | |||
Most Teltonika-Networks devices have the Modbus feature. Configuration is described in the user manual Services page for each device. | |||
Latest revision as of 19:47, 13 October 2024
The information on this page is updated in accordance with the 00.07.09 firmware version .
Summary
This article contains instructions on how to configure Modbus TCP functionality on most of the Teltonika Networks devices (with the exception of TAP and TSW series)
Configuration overview & prerequisites
Before we begin, let's take a look at the configuration that we are attempting to achieve and the prerequisites that make it possible.
Configuring port forwarding on Teltonika devices is a simple process that involves just a few steps and can easily be replicated across various devices. The number of devices involved will depend on the specific use case, but the setup can be scaled seamlessly. In the example below, we will use the RUTX50 as the Modbus TCP Client and RUT956 as Modbus TCP Server.
Prerequisites:
- A device from the RUT, RUTX, RUTM, RUTC or TRB series gateway;
- A PC, Laptop, tablet or a smartphone
- Router acting as Modbus TCP Server must have a SIM card with a Public Static or Public Dynamic IP address (more on IP address types here) to make remote access possible
- (Optional) If the router's SIM card has a Public Dynamic IP address, you may want to additionally configure a Dynamic DNS hostname
If you're having trouble finding this page or some of the parameters described here on your device's WebUI, you should turn on "Advanced WebUI" mode. You can do that by clicking the "Advanced" button, located at the top of the WebUI.
Modbus TCP Server
Configure Modbus TCP Server device. our slave device to have a 192.168.1.2 internal IP address. This can be done by changing the IP address parameter on Network → WAN page:
Modbus TCP Server configuration
Setup router as Modbus TCP Server. It can be done in Services → Modbus → Modbus TCP Server . Once in the Modbus TCP Server configuration, find the Enable the instance and turn on the Allow remote access. Everything else can be left as default or changed based on your needs:
Once finished click Save & Apply to save the configuration.
Remote access configuration
If you wish to remotely access the Modbus TCP Server device navigate to the System → Administration → Access Control tab. Once in the Administration-Access Control, find the Enable remote HTTP access field and put a check mark next to it:
Note: If you have a Public IP address already, you can skip this step.
To set the APN, while in the router's WebUI, navigate to the Network → Mobile → General → Interface mob1s1a1 APN configuration:
Once in the Interface mob1s1a1 APN configuration window, edit your mobile interface, find the APN field and enter you Internet Service Provider's APN:
- Disable the Auto APN option
- Choose the correct APN, which gives out a public IP address (for more information about that contact your Internet Service Provider)
Additional notes on APN:
- NOTE 1: don't use the exact APN value as seen in the example above as it will not work with your SIM card. APN depends on your Internet Service Provider (ISP), therefore, your ISP should provide you with their APN or, in many case, you can find your ISP's APN with an online search.
- NOTE 2: furthermore, it should be noted that not all SIM cards support this functionality. Static or Dynamic Public IP addresses (obtained through APN) are a paid service and setting any APN value for a SIM card that doesn't support this service will most likely result in losing your data connection. If this is the case, it can be fixed by simply deleting the APN, but it also means that remote access through mobile WAN IP will most likely not work on your SIM card.
- NOTE 3: in some cases the SIM card doesn't require an APN in order to obtain a Public IP address. If that is the case for you, simply check what your router's mobile WAN IP address is - if it's already a Public IP address, then you don't need to set an APN. The easiest way to find what your mobile WAN IP address is to log in to the router's WebUI and check the MOB1S1A1 widget in the Overview page:
Modbus TCP Client
Modbus TCP Client configuration
On the Modbus TCP Client device open Services → Modbus → Modbus TCP Client. To create a new instance click on Add. A new pop-up window should appear:
- Enable the instance
- Enter the desired name
- Server ID must match with the previously configured Server device ID
- Enter the mobile WAN IP address of the Modbus TCP Server device
- Chose same Port as in Server device - 502
- Enter Period in seconds, how often requests will be sent to the Server device
Requesting Modbus data
For testing, if the functionality is working we can configure a request. A Modbus request is a way of obtaining data from Modbus Server. The Client sends a request to a Server specifying the function code to be performed. The Server then sends the requested data back to the Modbus Client.
Scroll down to the Request configuration section. Write a name for the request and click the Add button:
In this case we are trying to get System temperature (in 0.1 °C) information so configure the next options:
- Data type: 32bit INT, Byte order 1,2,3,4
- Function: Read holding registers (3)
- First register: 6
- Number of registers: 2
- Enble brackets if not needed
- Enable the request
The information about correct Modbus registers usage can be found [here].
Under the Request Configuration section there will be another section called Request Configuration Testing this is where you can test that the parameters that you set work properly. Just select the request that you want to test and click the test button and you should get an output.
See Also
Most Teltonika-Networks devices have the Modbus feature. Configuration is described in the user manual Services page for each device.