Changes

m
Fix typo (switc -> switch)
Line 1: Line 1:  
Router monitoring via Modbus TCP Linux guide applies to RUT950 and RUT955 routers.[[File:Configuration examples modbus logo.png|right|300px]]
 
Router monitoring via Modbus TCP Linux guide applies to RUT950 and RUT955 routers.[[File:Configuration examples modbus logo.png|right|300px]]
   −
==Summary==
+
==Introduction==
    
'''Modbus''' is a serial communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). Modbus has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. The main reasons for the use of Modbus in the industrial environment are:
 
'''Modbus''' is a serial communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). Modbus has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. The main reasons for the use of Modbus in the industrial environment are:
   −
* developed with industrial applications in mind,
+
*developed with industrial applications in mind,
* openly published and royalty-free,
+
*openly published and royalty-free,
* easy to deploy and maintain,
+
*easy to deploy and maintain,
* moves raw bits or words without placing many restrictions on vendors.
+
*moves raw bits or words without placing many restrictions on vendors.
    
Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact.
 
Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact.
   −
This chapter is a guide on how to use Modbus TCP to monitor RUT950 and RUT955 routers using a Linux Operating System.
+
This article provides a guide on how to use Modbus TCP to monitor RUT955 routers with a PC using a Linux Operating System. However, the same principles apply to RUT230, RUT240 and RUT950 routers, but the holding register information will differ. You can find this information in the links below:
 +
 
 +
*'''[[RUT230 Modbus]]'''
 +
*'''[[RUT240 Modbus]]'''
 +
*'''[[RUT950 Modbus]]'''
    
==Configuring the router==
 
==Configuring the router==
   −
In order to start using Modbus TCP, we must first configure the router. Modbus TCP configuration from the router's side is very simple. All you need to do is log in to the router's WebUI, go to '''Services → Mobdus''', '''Enable''' the Modbus TCP service, enter a '''Port''' number through which the Modbus TCP communication will take place and '''Allow remote access''' if you wish to connect to the router remotely (from WAN).
+
In order to start using Modbus TCP, we must first configure the router. Modbus TCP configuration from the router's side is very simple. All you need to do is log in to the router's WebUI, go to '''Services → Modbus''', '''Enable''' the Modbus TCP service, enter a '''Port''' number through which the Modbus TCP communication will take place and '''Allow remote access''' if you wish to connect to the router remotely (from WAN).
 
  −
 
  −
[[File:Services modbus.PNG]]
      +
[[File:Services modbus v2.PNG]]
    
==Installing the necessary software==
 
==Installing the necessary software==
   −
Next you'll need software capable of communicating via Modbus TCP. The software that we'll be using for this guide is called '''modbus-cli'''. To get it you'll first have to install '''ruby'''. To do so, open the '''Terminal''' app and enter these commands.
+
Next you'll need software capable of communicating via Modbus. The software that we'll be using for this guide is called '''modbus-cli'''. To get it you'll first have to install '''ruby'''. To do so, open the '''Terminal''' app and enter these commands.
    
  $ sudo apt-get install ruby
 
  $ sudo apt-get install ruby
  $ sudo gem instal modbus-cli
+
  $ sudo gem install modbus-cli
    
==Getting router parameters==
 
==Getting router parameters==
   −
Modbus TCP can be used to both '''get''' and '''set''' certain router parameters. First lets do an overview of how to get parameters via Modbus TCP.  
+
Modbus TCP can be used to both '''get''' and '''set''' certain router parameters. First lets do an overview of how to obtain parameters via Modbus TCP. Please keep in mind that in order to get routers parameters when using '''[https://wiki.teltonika-networks.com/view/RUT955_Modbus#Requests_configuration Request Configuration]''' you need to use '''Register Number''' instead of '''Register Address'''.
    
===List of parameters===
 
===List of parameters===
 
----
 
----
Router parameters are held within '''registers'''. Each register contains 2 bytes of information. For simplification the number of registers for storing numbers is 2, while the number of registers for storing text information is 16. The register numbers and corresponding system values are described below:
+
Router parameters are held within '''registers'''. Each register contains 2 bytes of information. For simplification the number of registers for storing numerical values is 2, while the number of registers for storing text information is 16. The register addresses and corresponding system values are described in the table below:
   −
{| class="wikitable"
+
{{Template: Networking_rut955_manual_modbus_modbus_tcp_get_parameters_table}}
|+
  −
! style="width: 355px; background: black; color: white;"  | Required value
  −
! style="width: 170px; background: black; color: white;"  | Representation
  −
! style="width: 135px; background: black; color: white;"  | Register number
  −
! style="width: 162px; background: black; color: white;"  | Number of registers
  −
|-
  −
! style="text-align: left; vertical-align: top;" | System uptime
  −
| style="text-align: left; vertical-align: top;" | 32 bit unsigned integer
  −
| style="text-align: left; vertical-align: top;" | 1
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | GSM signal strength (dBm)
  −
| style="text-align: left; vertical-align: top;" | 32 bit integer
  −
| style="text-align: left; vertical-align: top;" | 3
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | System temperature in 0.1 degrees Celcius
  −
| style="text-align: left; vertical-align: top;" | 32 bit integer
  −
| style="text-align: left; vertical-align: top;" | 5
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | System hostname
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 7
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | GSM operator name
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 23
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Router serial number
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 39
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Router MAC address
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 55
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Router name
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 71
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Current SIM card
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 87
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Network registration
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 103
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Network type
  −
| style="text-align: left; vertical-align: top;" | Text
  −
| style="text-align: left; vertical-align: top;" | 119
  −
| style="text-align: left; vertical-align: top;" | 16
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Digital input 1
  −
| style="text-align: left; vertical-align: top;" | 32 bit integer
  −
| style="text-align: left; vertical-align: top;" | 135
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Digital input
  −
| style="text-align: left; vertical-align: top;" | 32 bit integer
  −
| style="text-align: left; vertical-align: top;" | 137
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Current WAN IP address
  −
| style="text-align: left; vertical-align: top;" | 32 bit unsigned integer
  −
| style="text-align: left; vertical-align: top;" | 139
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
! style="text-align: left; vertical-align: top;" | Analog input
  −
| style="text-align: left; vertical-align: top;" | 32 bit integer
  −
| style="text-align: left; vertical-align: top;" | 141
  −
| style="text-align: left; vertical-align: top;" | 2
  −
|-
  −
|}
      
===modbus read===
 
===modbus read===
Line 125: Line 45:  
To obtain parameters from the system, the '''modbus read''' command is used. The syntax for this command is:
 
To obtain parameters from the system, the '''modbus read''' command is used. The syntax for this command is:
   −
  $ modbus read [OPTIONS] HOST_NAME REGISTER_NUMBER NUMBER_OF_REGISTERS
+
  $ modbus read [OPTIONS] HOST_NAME REGISTER_ADDRESS NUMBER_OF_REGISTERS
    
'''OPTIONS''' can describe things like data type, port number, type of addressing, etc.  
 
'''OPTIONS''' can describe things like data type, port number, type of addressing, etc.  
Line 131: Line 51:  
'''HOST_NAME''' is the router's hostname or IP address (WAN IP, if you are connecting remotely).
 
'''HOST_NAME''' is the router's hostname or IP address (WAN IP, if you are connecting remotely).
   −
'''REGISTER_NUMBER''' specifies the register that you wish to read.
+
'''REGISTER_ADDRESS''' specifies the register that you wish to read.
   −
'''NUMBER_OF_REGISTERS''' specifies how many registers should be read starting from the register specified in '''REGISTER_NUMBER'''.
+
'''NUMBER_OF_REGISTERS''' specifies how many registers should be read starting from the register specified in '''REGISTER_ADDRESS'''.
   −
'''Note:''' all of this information and more can be viewed by entering this command: '''modbus read -h''' or '''modbus read --help'''.
+
'''Note:''' all of this information and more can be viewed by executing these commands in The Linux Terminal: '''modbus read -h''' or '''modbus read --help'''.
   −
For example, lets use this command to get the router's uptime value in seconds. If you look back at the table above, you will see that the uptime value is stored in two registers starting from the first register, therefore:
+
For the first example, lets use a modbus read command to attempt to obtain the router's uptime value in seconds. If you look back at the table above, you will see that the uptime value is stored in two registers starting from the first register, therefore:
    
  $ modbus read -w -p 12345 192.168.1.1 %MW001 2
 
  $ modbus read -w -p 12345 192.168.1.1 %MW001 2
Line 147: Line 67:  
'''192.168.1.1''' - the router's LAN IP address.
 
'''192.168.1.1''' - the router's LAN IP address.
   −
'''%MW001''' specifies the register number.
+
'''%MW001''' specifies the register address.
    
'''2''' - specifies how many registers should be read.
 
'''2''' - specifies how many registers should be read.
Line 203: Line 123:       −
These are examples of converting an eight-bit two's complement number to decimal. To do this, you first check if the number is negative or positive by looking at the sign bit. If it is positive, simply convert it to decimal. If it is negative, make it positive by inverting the bits and adding one. Then, convert the result to decimal. The negative of this number is the value of the original binary.
+
To change the '''sing''' of a binary number you must invert it add 1 to it. In the case of signal strength, you don't need both register values to do so, only the second one (register 4), which is, in our example, 65477. When converted to binary it's: '''65447 → 1111 1111 1100 0101'''. Next, we'll to invert it and add 1:
 +
 
 +
 
 +
[[File:Configuration examples modbus negative binary.png]]
 +
 
 +
 
 +
The value we got is '''0000 0000 0011 1011'''. When converted to decimal it becomes '''59''', so the final value is '''- 59'''
 +
 
 +
===Text===
 +
----
 +
Some values like Hostname, Router name, Network type are represented as text in their original form, but are stored in registers as numbers. You can interpret these values the same way as all discussed before (by converting them to binary and then to text), but a simpler way would be to get them in '''hexadecimal''' form and then convert them to text. To do so, we'll have to add the '''-D''' parameter to the command. Lets do it by asking for the router's Hostname:
 +
 
 +
$ modbus read -D -w -p 12345 192.168.1.1 %MW007 16
 +
 
 +
[[Image:Configuration examples modbus hostname example v2.png]]
 +
 
 +
Ignore the first 9 segments and the last segments that contain only zeroes (highlighted in red). Copy the response (highlighted in green) and paste it into a hexadecimal to text (ASCII) converter:
 +
 
 +
[[Image:Configuration examples modbus hex to text.png]]
 +
 
 +
==Setting router values==
 +
 
 +
The Modbus daemon also supports the setting of some system parameters. To accomplish this task the '''modbus write''' command is used. System related parameters and how to use them are described below. The register address specifies from which register to start writing the required values. All commands, except “Change APN”, accepts only one input parameter (more on changing APN can be found below). 
 +
 
 +
{{Template: Networking_rut955_manual_modbus_modbus_tcp_set_parameters_table}}
 +
 
 +
As you can see most of the values are '''0''' and '''1''', 0 meaning OFF and 1 meaning ON. For example, if you want to turn '''WiFi OFF''', this command should be used:
 +
 
 +
$ modbus write -w -p 12345 192.168.1.1 %MW203 0
 +
 
 +
If you want to turn '''WiFi ON''', use this command instead:
 +
 
 +
$ modbus write -w -p 12345 192.168.1.1 %MW203 1
 +
 
 +
As you can see, the only difference is the digit at the end - '''0 for OFF''', '''1 for ON'''. The same is true for all other parameters that accept only two input values.
 +
 
 +
In the case of '''SIM switch''' there are three values - '''0''', '''1''' and '''2'''. 1 makes the first SIM card slot in use, 2 makes the second SIM card slot in use and 0 initiates a switch from the SIM card in use to the opposite SIM card. For example, to initiate a switch to the second SIM card the command should look like this:
 +
 
 +
$ modbus write -w -p 12345 192.168.1.1 %MW205 2
 +
 
 +
The '''reboot''' function only takes one value: '''1'''. It simply reboots the router. To initiate a reboot, use this command:
 +
 
 +
$ modbus write -w -p 12345 192.168.1.1 %MW206 1
 +
 
 +
===APN===
 +
----
 +
APN is the only parameter that can accept more than one input value. For the APN parameter the number of input registers may vary. The very first byte of an APN command denotes the number of the SIM card for which the APN will be set. This byte should be set to 1 (in order to set the APN for SIM card number 1) or to 2 (in order to set the APN for SIM card number 2). The rest of the string should be entered one symbol at a time. Each symbol should be converted from ASCII (regular text) to decimal.
 +
 
 +
As an example lets try to change the router's first SIM card's APN to '''gprs.fix-ip.omnitel1.net''':
 +
 
 +
$ modbus write -w -D -p 12345 192.168.1.1 %MW207 <span style="color:blue">'''1'''</span> <span style="color:green">'''103 112 114 115 46 102 105 120 45 105 112 46 111 109 110 105 116 101 108 49 46 110 101 116'''</span>
 +
 
 +
The value of the first byte is highlighted in <span style="color:blue">'''blue'''</span> and, in this case, it denotes that the APN value should be changed for the first SIM card. The value of the APN string itself is highlighted in <span style="color:green">'''green'''</span>. Use an ASCII to Decimal online converter to convert individual letters to Decimal code.
 +
 
 +
==External links==
   −
    Interpret 11011011 as a two's complement binary number, and give its decimal equivalent.
+
*Online unit converters:
        First, note that the number is negative, since it starts with a 1.
+
**http://www.unit-conversion.info/
        Change the sign to get the magnitude of the number.
+
**http://www.binaryhexconverter.com/
0

edits