Line 955: |
Line 955: |
| </tr> | | </tr> |
| </table> | | </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>if modbus function is <b>3</b> - <u>register count</u> (in range [1..125]); must not exceed the boundary (first register number + register count <= 65537);</li> |
| + | <li>if modbus function is <b>6</b> - <u>register value</u> (in range [0..65535]);</li> |
| + | <li>if modbus function is <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== |