Difference between revisions of "RUTX09 Modbus"
|Line 2:||Line 2:|
| name = RUTX09
| name = RUTX09
| series = RUTX
| series = RUTX
Revision as of 14:08, 15 July 2020Main Page > RUTX Routers > RUTX09 > RUTX09 Manual > RUTX09 WebUI > RUTX09 Services section > RUTX09 Modbus
The information in this page is updated in accordance with firmware version RUTX_R_00.07.02.
Modbus is a serial communications protocol. Simple and robust, it has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices.
This manual page provides an overview of the Modbus functionality in RUTX09 devices.
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 "Basic" button under "Mode", which is located at the top-right corner of the WebUI.
Modbus TCP slave
A Modbus TCP slave listens for connections from a master (client) and sends out a response or sets some system related parameter in accordance with the given query. This provides the user with the possibility to set or get system parameters.
The figure below is an example of the Modbus TCP window section and the table below provides information on the fields contained in that window:
|Enable||off | on; default: off||Turns Modbus TCP on or off.|
|Port||integer [0..65535]; default: 502||TCP port used for Modbus communications.|
|Device ID||integer [0..255]; default: 1||The device's Modbus slave ID. When set to 0, it will respond to requests addressed to any ID.|
|Allow Remote Access||off | on; default: off||Allows remote Modbus connections by adding an exception to the device's firewall on the port specified in the field above.|
|Keep persistent connection||off | on; default: off||Allows keep the connection open after responding a Modbus TCP master request.|
|Connection timeout||integer; default: 0||Sets TCP timeout in seconds after which the connection is forcefully closed.|
|Enable custom register block||off | on; default: off||Allows the usage of custom register block.|
Modbus parameters are held within registers. Each register contains 2 bytes of information. For simplification, the number of registers for storing numbers is 2 (4 bytes), while the number of registers for storing text information is 16 (32 bytes). The register numbers and corresponding system values are described in the table below:
|required value||register address||register number||number of registers||representation|
|System uptime||1||2||2||32 bit unsigned integer|
|Mobile signal strength (RSSI in dBm)||3||4||2||32 bit integer|
|System temperature (in 0.1 °C)||5||6||2||32 bit integer|
|GSM operator name||23||24||16||Text|
|Router serial number||39||40||16||Text|
|LAN MAC address||55||56||16||Text|
|Network registration info||103||104||16||Text|
|Current WAN IP address||139||140||2||8 bit unsigned integer|
|GPS latitude coordinate||143||144||2||32 bit float|
|GPS longitude coordinate||145||146||2||32 bit float|
|GPS fix time||147||148||16||Text (Unix timestamp×1000)|
|GPS date and time||163||164||16||Text (DDMMYYhhmmss)|
|GPS speed||179||180||2||32 bit float|
|GPS satellite count||181||182||2||32 bit unsigned integer|
|GPS accuracy||183||184||2||32 bit float|
|Mobile data received today (SIM1)||185||186||2||32 bit unsigned integer|
|Mobile data sent today (SIM1)||187||188||2||32 bit unsigned integer|
|Mobile data received this week (SIM1)||189||190||2||32 bit unsigned integer|
|Mobile data sent this week (SIM1)||191||192||2||32 bit unsigned integer|
|Mobile data received this month (SIM1)||193||194||2||32 bit unsigned integer|
|Mobile data sent this month (SIM1)||195||196||2||32 bit unsigned integer|
|Mobile data received last 24h (SIM1)||197||198||2||32 bit unsigned integer|
|Mobile data sent last 24h (SIM1)||199||200||2||32 bit unsigned integer|
|Mobile data received last week (SIM1)||292||293||2||32 bit unsigned integer|
|Mobile data sent last week (SIM1)||294||295||2||32 bit unsigned integer|
|Mobile data received last month (SIM1)||296||297||2||32 bit unsigned integer|
|Mobile data sent last month (SIM1)||298||299||2||32 bit unsigned integer|
|Mobile data received today (SIM2)||300||301||2||32 bit unsigned integer|
|Mobile data sent today (SIM2)||302||303||2||32 bit unsigned integer|
|Mobile data received this week (SIM2)||304||305||2||32 bit unsigned integer|
|Mobile data sent this week (SIM2)||306||307||2||32 bit unsigned integer|
|Mobile data received this month (SIM2)||308||309||2||32 bit unsigned integer|
|Mobile data sent this month (SIM2)||310||311||2||32 bit unsigned integer|
|Mobile data received last 24h (SIM2)||312||313||2||32 bit unsigned integer|
|Mobile data sent last 24h (SIM2)||314||315||2||32 bit unsigned integer|
|Mobile data received last week (SIM2)||316||317||2||32 bit unsigned integer|
|Mobile data sent last week (SIM2)||318||319||2||32 bit unsigned integer|
|Mobile data received last month(SIM2)||320||321||2||32 bit unsigned integer|
|Mobile data sent last month (SIM2)||322||323||2||32 bit unsigned integer|
|Digital non-isolated input (4 PIN connector)||324||325||1||16 bit unsigned integer|
|Digital open collector output (4 PIN connector)||325||326||1||16 bit unsigned integer|
|Unix timestamp||364||365||2||32 bit unsigned integer|
|Local ISO time||366||367||12||Text|
The Modbus daemon can also set some device parameters.
|value to set||register address||register number||register value||description|
|Hostname||7||8||Hostname (in decimal form)||Changes hostname|
|Device name||71||72||Device name (in decimal form)||Changes device name|
|Switch mobile data connection (ON/OFF*)||204||205||1 | 0||Turns mobile data connection ON or OFF|
|Reboot||206||207||1||Reboots the router|
|Change APN||207||208||APN code||Changes APN.
The number of input registers may vary depending on the length of the APN, but the very first byte of the set APN command denotes the number of the SIM card for which to set the APN. This byte should be set to:
|Switch PIN 4 state||325||326||1|0||Toggles PIN 4 ON or OFF|
Modbus TCP Master
A Modbus Master device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves. By default, the slave list is empty. To add a new slave, click the 'Add' button
After clicking 'Add' you will be redirected to the newly added slave's configuration page.
You can create a maximum of 10 slave configurations.
Slave Device Configuration
The Slave Device Configuration section is used to configure the parameters of Modbus TCP slaves that the Master (this RUTX09 device) will be querying with requests. The figure below is an example of the Slave Device Configuration and the table below provides information on the fields contained in that section:
|Enabled||off | on; default: off||Turns communication with the slave device on or off.|
|Name||string; default: none||Slave device's name, used for easier management purposes.|
|Slave ID||integer [0..255]; default: none||Slave ID. Each slave in a network is assigned a unique identifier ranging from 1 to 255. When the master requests data from a slave, the first byte it sends is the Slave ID. When set to 0, the slave will respond to requests addressed to any ID.|
|IP address||ip; default: none||Slave device's IP address.|
|Port||integer [0..65535]; default: none||Slave device's Modbus TCP port.|
|Period||integer [1..86400]; default: 60||Interval at which requests are sent to the slave device.|
|Timeout||integer [1..30]; default: 5||Maximum response wait time.|
A Modbus request is a way of obtaining data from Modbus slaves. The master sends a request to a slave specifying the function code to be performed. The slave then sends the requested data back to the Modbus master. You can create a maximum of 64 request configurations for each slave device.
Note: Modbus TCP Master uses Register Number instead of Register Address for pointing to a register. For example, to request the Uptime of a device, you must use 2 in the First Register field.
The Request Configuration list is empty by default. To add a new Request Configuration loon to the Add New Instance section. Enter a custom name into the 'Name' field and click the 'Add' button:
The new Request Configuration should become visible in the list:
|Name||string; default: Unnamed||Name of this Request Configuration. Used for easier management purposes.|
|Data type||8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float, Byte order 1,2,3,4 | 32bit float, Byte order 4,3,2,1 | 32bit float, Byte order 2,1,4,3 | 32bit float, Byte order 3,4,1,2; default: 16bit INT, high byte first||Defines how read data will be stored.|
|Function||Read coils (1) | Read input coils (2) | Read holding registers (3) | Read input registers (4) | Set single coil (5) | Set single coil register (6) | Set multiple coils (15) | Set multiple holding registers (16); default: Read holding registers (3)||Specifies the type of register being addressed by a Modbus request.|
|First Register||integer [0..65535]; default: 1||First Modbus register from which data will be read.|
|Register Count / Values||integer [1..2000]; default: 1||Number of Modbus registers that will be read during the request.|
|No Brackets||off | on; default: off||Removes the starting and ending brackets from the request (only for read requests).|
|Delete [ X ]||- (interactive button)||Deletes the request.|
|off/on slider||off | on; default: off||Turns the request on or off.|
Additional note: by default the newly added Request Configurations are turned off. You can use the on/off slider to the right of the Request Configuration to turn it on:
After having configured a request, you should see a new 'Request Configuration Testing' section appear. It is used to check whether the configuration works correctly. Simply click the 'Test' button and a response should appear in the box below. A successful response to a test may look something like this:
Alarms are a way of setting up automated actions when some Modbus values meet user-defined conditions. When the Modbus TCP Master (this RUTX09 device) requests some information from a slave device it compares that data to with the parameters set in an Alarm Configuration. If the comparison meets the specified condition (more than, less than, equal to, not equal to), the Master performs a user-specified action, for example, a Modbus write request or switching the state of an output.
The figure below is an example of the Alarms Configuration list. To create a new Alarm, click the 'Add' button.
After adding the Alarm you should be redirected to its configuration page which should look similar to this:
|Enabled||off | on; default: off||Turns the alarm on or off.|
|Function code||Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4); default: Read Coil Status (1)||Modbus function used for this alarm's Modbus request. The Modbus TCP Master (this RUTX09 device) perform this request as often as specified in the 'Period' field in Slave Device Configuration.|
|Register||integer [1..65536]; default: none||Number of the Modbus coil/input/holding-register/input-register to read from.|
|Condition||More than | Less than | Equal to | Not Equal to; default: Equal to||When a value is obtained it will be compared against the value specified in the following field. The comparison will be made in accordance with the condition specified in this field.|
|Value||various; default: none||The value against which the read data will be compared.|
|Value||integer [0..65535]; default: none||The value against which the read data will be compared.|
|Action frequency||Every trigger | First trigger; default: Every trigger||Describes how frequently the specified action will be taken.|
|Redundancy protection||off | on; default: off||Protection against executing a configured action too often.|
|Redundancy protection period||integer [1..86400]; default: none||Duration to activate redundancy protection for, measured in seconds. This field becomes visible only when 'Redundancy protection' is turned on.|
|Action||SMS | MODBUS Write Request| Trigger output; default: MODBUS Write Request||Action that will be taken if the condition is met. Possible actions:
|SMS: Message||string; default: none||SMS message text.|
|SMS: Phone number||phone number; default: none||Recipient's phone number.|
|MODBUS Write Request: IP address||ip | host; default: none||Modbus slave's IP address.|
|MODBUS Write Request: Port||integer [0..65535]; default: none||Modbus slave's port.|
|MODBUS Write Request: Timeout||integer [1..30]; default: 5||Maximum time to wait for a response.|
|MODBUS Write Request: ID||integer [1..255]; default: none||Modbus slave ID.|
|MODBUS Write Request: Modbus function||Read Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); default: Force Single Coil (5)||A function code specifies the type of register being addressed by a Modbus request.|
|MODBUS Write Request: First register||integer [0..65535]; default: none||Begins reading from the register specified in this field.|
|MODBUS Write Request: Values||integer [0..65535]; default: none||Register/Coil values to be written (multiple values must be separated by space character).|
|Trigger output: Output||4PIN output; default: 4PIN output||Selects which output will be triggered.|
|Trigger output: I/O Action||Turn On | Turn Off | Invert; default: Turn On||Selects the action performed on the output.|
The MQTT Gateway function is used to transfer Modbus data (send requests, receive responses) over MQTT. When it is enabled, the device (this RUTX09) subscribes to a REQUEST topic and publishes on a RESPONSE topic on a specified MQTT broker. It translates received MQTT message payload to a Modbus request and relays it to the specified Modbus TCP slave.
When the MQTT Gateway receives a response from the slave, it translates it to an MQTT message and publishes it on the RESPONSE topic.
Below is an example of the MQTT Gateway page. Refer to the table for information on MQTT Gateway configuration fields.
|Enable||off | on; default: off||Turns MQTT gateway on or off.|
|Host||ip | host; default: 127.0.0.1||IP address or hostname of an MQTT broker.|
|Port||integer [0..65535]; default: 1883||Port number of the MQTT broker.|
|Request topic||alphanumeric string; default: request||MQTT topic for sending requests.|
|Response topic||alphanumeric string; default: response||MQTT topic for subscribing to responses.|
|Username||string; default: none||Username for authentication to the MQTT broker.|
|Password||string; default: none||Password for authentication to the MQTT broker.|
Note: MQTT Gateway uses Register Number instead of Register Address for pointing to a register. For example, to request the Uptime of a device, you must use 2 in the Register Number field.
Modbus request data sent in the MQTT payload should be generated in accordance with the following format:
0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE>
- 0 - must be 0, which signifies a textual format (currently the only one implemented).
- Cookie - a 64-bit unsigned integer in range [0..264]). A cookie is used in order to distinguish which response belongs to which request, each request and the corresponding response contain a matching cookie: a 64-bit unsigned integer.
- IP type - host IP address type. Possible values:
- 0 - IPv4 address;
- 1 - IPv6 address;
- 2 - hostname that will be resolved to an IP address.
- IP - IP address of a Modbus TCP slave. IPv6 must be presented in full form (e.g., 2001:0db8:0000:0000:0000:8a2e:0370:7334).
- Port - port number of the Modbus TCP slave.
- Timeout - timeout for Modbus TCP connection, in seconds. Range [1..999].
- Slave ID - Modbus TCP slave ID. Range [1..255].
- Modbus function - Modbus task type that will be executed. Possible values are:
- 3 - read holding registers;
- 6 - write to a single holding register;
- 16 - write to multiple holding registers.
- Register number - number (not address) of the first register (in range [1..65536]) from which the registers will be read/written to.
- Register count/value - this value depends on the Modbus function:
- 3 - register count (in range [1..125]); must not exceed the boundary (first register number + register count <= 65537);
- 6 - register value (in range [0..65535]);
- 16 - register count (in range [1..123]); must not exceed the boundary (first register number + register count <= 65537); and register values separated with commas, without spaces (e.g., 1,2,3,654,21,789); there must be exactly as many values as specified (with register count); each value must be in the range of [0..65535].
A special response message can take one of the following forms:
<COOKIE> OK - for functions 6 and 16 <COOKIE> OK <VALUE> <VALUE> <VALUE>... - for function 3, where <VALUE> <VALUE> <VALUE>... are read register values <COOKIE> ERROR: ... - for failures, where ... is the error description
Below are a few examples of controlling/monitoring the internal Modbus TCP Slave on RUTX09.
Reboot the device
0 65432 0 192.168.1.1 502 5 1 6 206 1
0 65432 0 192.168.1.1 502 5 1 3 2 2
65432 OK 0 5590
If you're using Eclipse Mosquitto (MQTT implementation used on RUTX09), Publish/Subscribe commands may look something like this:
mosquitto_pub -h 192.168.1.1 -p 1883 -t request -m "0 65432 0 192.168.1.1 502 5 1 3 2 2"
mosquitto_sub -h 192.168.1.1 -p 1883 -t response 65432 OK 0 5590
- Monitoring via Modbus - detailed examples on how to use Modbus TCP