Jump to content

Template:Networking rut manual modbus: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
{{Template: Networking_rutxxx_manual_fw_disclosure
{{Template: Networking_rutxxx_manual_fw_disclosure
| fw_version = {{#switch: {{{series}}}
| fw_version = {{#switch: {{{series}}}
   | RUT2 = {{{series}}}_R_00.01.12
   | RUT2 = {{{series}}}_R_00.01.13
   | RUT9 = {{{series}}}_R_00.06.07}}
   | RUT9 = {{{series}}}_R_00.06.07}}
| series    = {{{series}}}
| series    = {{{series}}}
Line 51: Line 51:
==Modbus TCP Master==
==Modbus TCP Master==


A Modbus <b>master</b> device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves. To add a new slave, enter a custom name, slave's ID, IP address and port and click the "Add" button:
A Modbus <b>master</b> device can request data from Modbus slaves. The Modbus TCP Master section is used to configure Modbus TCP slaves.  
[[File:{{{file_add_new_slave}}}]]
 
<table class="nd-othertables_2">
    <tr>
        <th width=250>Button</th>
        <th width=902>Description</th>
    </tr>
    <tr>
        <td><b>Edit</b></td>
        <td>Redirects you to the slave's configuration page (more information in [[{{{name}}} Modbus#Slave_device_configuration|section 3.1]])</td>
    </tr>
    <tr>
        <td><b>Delete</b></td>
        <td>Deletes the slave configuration</td>
    </tr>
    <tr>
        <td><b>Alarms</b></td>
        <td>Redirects you to the slave's alarm configuration page (more information in [[{{{name}}} Modbus#Alarm_configuration|section 3.3]])</td>
    </tr>
    <tr>
        <td><b>Clone</b></td>
        <td>Creates an identical slave configuration</td>
    </tr>
</table>
 
You can create a maximum of 10 slave configurations.
You can create a maximum of 10 slave configurations.


Line 171: Line 146:
         <td>First Register</td>
         <td>First Register</td>
         <td>integer [1..65536]; default: <b>1</b></td>
         <td>integer [1..65536]; default: <b>1</b></td>
         <td>First Modbus register number from which data will be read.<br>'''Note.:''' {{{series}}} Modbus Master uses register numbers, which value is +1 higher than address value.</br></td>
         <td>First Modbus register number from which data will be read.<br>'''Note''' - {{{series}}} Modbus Master uses register numbers, which value is +1 higher than address value.</br></td>
     </tr>
     </tr>
     <tr>
     <tr>
Line 239: Line 214:
     <tr>
     <tr>
         <td>Action</td>
         <td>Action</td>
         <td>SMS | Trigger output | Modbus Request; default: <b>SMS</b></td>
         <td><span style="color: #0054a6; font-weight:bold;">SMS</span> | <span style="color: red; font-weight:bold;">Trigger output</span> | <span style="color: purple; font-weight:bold;">Modbus Request</span>; default: <b>SMS</b></td>
         <td>Action that will be taken if the condition is met. Possible actions:
         <td>Action that will be taken if the condition is met. Possible actions:
             <ul>
             <ul>
Line 249: Line 224:
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: #0054a6;">SMS: Message</span></td>
         <td><span style="color: #0054a6;">SMS:</span> Message</td>
         <td>string; default: <b>none</b></td>
         <td>string; default: <b>none</b></td>
         <td>SMS message text.</td>
         <td>SMS message text.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: #0054a6;">SMS: Phone number</span></td>
         <td><span style="color: #0054a6;">SMS:</span> Phone number</td>
         <td>phone number; default: <b>none</b></td>
         <td>phone number; default: <b>none</b></td>
         <td>Recipient's phone number.</td>
         <td>Recipient's phone number.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: red;">Trigger output: Output</span></td>
         <td><span style="color: red;">Trigger output:</span> Output</td>
         <td>Open collector output | Relay output | Both; default: <b>Open collector output</b></td>
         <td>Open collector output | Relay output | Both; default: <b>Open collector output</b></td>
         <td>Which output(s) will be triggered.</td>
         <td>Which output(s) will be triggered.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: red;">Trigger output: I/O Action</span></td>
         <td><span style="color: red;">Trigger output:</span> I/O Action</td>
         <td>Turn On | Turn Off | Invert; default: <b>Turn On</b></td>
         <td>Turn On | Turn Off | Invert; default: <b>Turn On</b></td>
         <td>Action that will taken on the specified output.</td>
         <td>Action that will taken on the specified output.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: IP address</span></td>
         <td><span style="color: purple;">Modbus Request:</span> IP address</td>
         <td>ip | host; default: <b>none</b></td>
         <td>ip | host; default: <b>none</b></td>
         <td>Modbus slave's IP address.</td>
         <td>Modbus slave's IP address.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Port</span></td>
         <td><span style="color: purple;">Modbus Request:</span> Port</td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>Modbus slave's port.</td>
         <td>Modbus slave's port.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Timeout</span></td>
         <td><span style="color: purple;">Modbus Request:</span> Timeout</td>
         <td>integer [1..30]; default: <b>5</b></td>
         <td>integer [1..30]; default: <b>5</b></td>
         <td>Maximum time to wait for a response.</td>
         <td>Maximum time to wait for a response.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: ID</span></td>
         <td><span style="color: purple;">Modbus Request:</span> ID</td>
         <td>integer [1..255]; default: <b>none</b></td>
         <td>integer [1..255]; default: <b>none</b></td>
         <td>Modbus slave ID.</td>
         <td>Modbus slave ID.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Modbus function</span></td>
         <td><span style="color: purple;">Modbus Request:</span> Modbus function</td>
         <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4) | Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); default: <b>Force Single Coil (5)</b></td>
         <td>Read Coil Status (1) | Read Input Status (2) | Read Holding Registers (3) | Read Input Registers (4) | Force Single Coil (5) | Preset Single Register (6) | Force Multiple Coils (15) | Force Multiple Registers (16); default: <b>Force Single Coil (5)</b></td>
         <td>A function code specifies the type of register being addressed by a Modbus request.</td>
         <td>A function code specifies the type of register being addressed by a Modbus request.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: First register</span></td>
         <td><span style="color: purple;">Modbus Request:</span> First register</td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>Begins reading from the register specified in this field.</td>
         <td>Begins reading from the register specified in this field.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td><span style="color: purple;">Modbus Request: Number of registers</span></td>
         <td><span style="color: purple;">Modbus Request:</span> Number of registers</td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>integer [0..65535]; default: <b>none</b></td>
         <td>The number of registers that will be read from the first register.</td>
         <td>The number of registers that will be read from the first register.</td>
Line 346: Line 321:
     <tr>
     <tr>
         <td>Protocol</td>
         <td>Protocol</td>
         <td>HTTP(S) | MQTT; Default: <b>HTTP(S)</b></td>
         <td><span style="color:tomato; font-weight:bold;">HTTP(S)</span> | <span style="color:darkcyan; font-weight:bold;">MQTT</span>; Default: <b>HTTP(S)</b></td>
         <td>Data sending protocol</td>
         <td>Data sending protocol</td>
     </tr>
     </tr>
Line 413: Line 388:
     </tr>
     </tr>
</table>
</table>
==MQTT Gateway==
The <b>MQTT Gateway</b> function is used to transfer Modbus data (send requests, receive responses) over MQTT. When it is enabled, the device (this {{{name}}}) 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.
[[File:Networking_rutos_manual_modbus_mqtt_gateway_scheme.png]]
Below is an example of the MQTT Gateway page. Refer to the table for information on MQTT Gateway configuration fields.
[[File:Networking_rut9_manual_modbus_mqtt_gateway_v1.png|border|class=tlt-border]]
<table class="nd-mantable">
    <tr>
        <th>Field</th>
        <th>Value</th>
        <th>Description</th>
    </tr>
    <tr>
        <td>Enable</td>
        <td>off <nowiki>|</nowiki> on; default: <b>off</b></td>
        <td>Turns MQTT gateway on or off.</td>
    </tr>
    <tr>
        <td>Host</td>
        <td>ip <nowiki>|</nowiki> host; default: <b>127.0.0.1</b></td>
        <td>IP address or hostname of an MQTT broker.</td>
    </tr>
    <tr>
        <td>Port</td>
        <td>integer [0..65535]; default: <b>1883</b></td>
        <td>Port number of the MQTT broker.</td>
    </tr>
    <tr>
        <td>Request topic</td>
        <td>string; default: <b>request</b></td>
        <td>MQTT topic for sending requests.</td>
    </tr>
    <tr>
        <td>Response topic</td>
        <td>string; default: <b>response</b></td>
        <td>MQTT topic for subscribing to responses.</td>
    </tr>
    <tr>
        <td>Username</td>
        <td>string; default: <b>none</b></td>
        <td>Username for authentication to the MQTT broker. Leave empty if you do not use client authentication.</td>
    </tr>
    <tr>
        <td>Password</td>
        <td>string; default: <b>none</b></td>
        <td>Password for authentication to the MQTT broker. Leave empty if you do not use client authentication.</td>
    </tr>
</table>
===Request messages===
----
Modbus request data sent in the MQTT payload should be generated in accordance with the following format:
<b>0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE></b>
Explanation:
<ul>
    <li><b>0</b> - must be 0, which signifies a textual format (currently the only one implemented).</li>
    <li><b>Cookie</b> - a 64-bit unsigned integer in range [0..2<sup>64</sup>]). 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.</li>
    <li><b>IP type</b> - host IP address type. Possible values:
        <ul>
            <li><b>0</b> - IPv4 address;</li>
            <li><b>1</b> - IPv6 address;</li>
            <li><b>2</b> - hostname that will be resolved to an IP address.</li>
        </ul></li>
    <li><b>IP</b> - IP address of a Modbus TCP slave. IPv6 must be presented in full form (e.g., <i>2001:0db8:0000:0000:0000:8a2e:0370:7334</i>).</li>
    <li><b>Port</b> - port number of the Modbus TCP slave.</li>
    <li><b>Timeout</b> - timeoutfor Modbus TCP connection, in seconds. Range [1..999].</li>
    <li><b>Slave ID</b> - Modbus TCP slave ID. Range [1..255].</li>
    <li><b>Modbus function</b> -  Only these are supported at the moment:
        <ul>
            <li><b>3</b> - read holding registers;</li>
            <li><b>6</b> - write to a single holding register;</li>
            <li><b>16</b> - write to multiple holding registers.</li>
        </ul></li>
    <li><b>Register number</b> - number of the first register (in range [1..65536]) from which the registers will be read/written to.
    <li><b>Register count/value</b> - this value depends on the Modbus function:
        <ul>
            <li><b>3</b> - <u>register count</u> (in range [1..125]); must not exceed the boundary (first register number + register count <= 65537);</li>
            <li><b>6</b> - <u>register value</u> (in range [0..65535]);</li>
            <li><b>16</b> - <u>register count</u> (in range [1..123]); must not exceed the boundary (first register number + register count <= 65537); and <u>register values</u> separated with commas, without spaces (e.g., <i>1,2,3,654,21,789</i>); there must be exactly as many values as specified (with register count); each value must be in the range of [0..65535].</li>
        </ul></li>
</ul>
===Response messages===
----
A special response message can take one of the following forms:
<COOKIE> OK                              - <i>for functions 6 and 16</i>
<COOKIE> OK <VALUE> <VALUE> <VALUE>...  - <i>for function 3, where <VALUE> <VALUE> <VALUE>... are read register values</i>
<COOKIE> ERROR: ...                      - <i>for failures, where ... is the error description</i>
===Examples===
----
Below are a few <b>examples</b> of controlling/monitoring the internal Modbus TCP Slave on {{{name}}}.
----
<b>Reboot the device</b>
<ul>
    <li>Request:<br><pre>0 65432 0 192.168.1.1 502 5 1 6 206 1</pre></li>
    <li>Response:<br><pre>65432 OK</pre></li>
</ul>
----
<b>Retrieve uptime</b>
<ul>
    <li>Request:<br><pre>0 65432 0 192.168.1.1 502 5 1 3 2 2</pre></li>
    <li>Response:<br><pre>65432 OK 0 5590</pre></li>
</ul>
----
If you're using Eclipse Mosquitto (MQTT implementation used on {{{name}}}), Publish/Subscribe commands may look something like this:
<b>Retrieve uptime</b>
<ul>
    <li>Request:<br><pre>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"</pre></li>
    <li>Response:<br><pre>mosquitto_sub -h 192.168.1.1 -p 1883 -t response
65432 OK 0 5590</pre></li>
</ul>


==See also==
==See also==
0

edits