Changes

no edit summary
Line 1: Line 1:  +
__TOC__
 
==Summary==
 
==Summary==
 
In this guide Modbus TCP master MQTT Gateway function will be configured with two different types of MQTT Brokers. First using third party MQTT Broker services (in this example ''Flespi.io''). Second using RUT240 router as MQTT Broker. Two RUT955 routers will be used as Modbus TCP Master and Slave, and PC acts as MQTT Publisher and Subscriber.
 
In this guide Modbus TCP master MQTT Gateway function will be configured with two different types of MQTT Brokers. First using third party MQTT Broker services (in this example ''Flespi.io''). Second using RUT240 router as MQTT Broker. Two RUT955 routers will be used as Modbus TCP Master and Slave, and PC acts as MQTT Publisher and Subscriber.
Line 6: Line 7:     
===Configuring RUT955 Modbus TCP Slave ===
 
===Configuring RUT955 Modbus TCP Slave ===
 +
----
 
Go to '''Services > Modbus > Modbus TCP Slave''':
 
Go to '''Services > Modbus > Modbus TCP Slave''':
    
#Check '''Enable'''
 
#Check '''Enable'''
# Enter port that will be used, in this example 502 will be used
+
#Enter port that will be used, in this example 502 will be used
# Enter device ID
+
#Enter device ID
 
#Press '''Save & Apply'''
 
#Press '''Save & Apply'''
[[File:Networking_MQTT_MODBUS_flespi_configuration_slave1_v1.png|alt=|border|1120x1120px]]
+
[[File:Networking_MQTT_MODBUS_flespi_configuration_slave1_v1.png|border|class=tlt-border|1120x1120px]]
    
''*In this config LAN port is used so “Allow Remote Access” is not needed''
 
''*In this config LAN port is used so “Allow Remote Access” is not needed''
Line 18: Line 20:  
''Modbus TCP Slave RUT955 is now configured''.
 
''Modbus TCP Slave RUT955 is now configured''.
   −
===Configuring RUT955 Modbus TCP Master ===
+
===Configuring RUT955 Modbus TCP Master===
 +
----
 
Go to '''Services > Modbus > Modbus TCP Master'''
 
Go to '''Services > Modbus > Modbus TCP Master'''
    
#Press '''Add'''
 
#Press '''Add'''
 
#Check '''Enable'''
 
#Check '''Enable'''
# Enter name for slave device
+
#Enter name for slave device
# Slave ID must match with previously configured Slave device ID
+
#Slave ID must match with previously configured Slave device ID
 
#Enter IP address of Modbus TCP Slave device
 
#Enter IP address of Modbus TCP Slave device
 
#Chose same Port as in Slave device - 502
 
#Chose same Port as in Slave device - 502
#Enter Period in seconds, how often requests will be sent to Slave device
+
# Enter Period in seconds, how often requests will be sent to Slave device
 
#Enter new request name and press '''Add''' in Requests configurations
 
#Enter new request name and press '''Add''' in Requests configurations
 
#Choose Data type and Function, enter First register/coil/input to be read or written and Register count. You can name each individual configuration, and then select enable on configurations that you want to use. In this example, register to get WAN IP address of the slave device is used.
 
#Choose Data type and Function, enter First register/coil/input to be read or written and Register count. You can name each individual configuration, and then select enable on configurations that you want to use. In this example, register to get WAN IP address of the slave device is used.
Line 35: Line 38:     
===Configuring Flespi.io MQTT Broker===
 
===Configuring Flespi.io MQTT Broker===
 +
----
 
Login or create an account on https://flespi.io
 
Login or create an account on https://flespi.io
   Line 52: Line 56:     
===Configuring MQTT Gateway on RUT955 Modbus TCP Master===
 
===Configuring MQTT Gateway on RUT955 Modbus TCP Master===
 +
----
 
Open routers WebUI and navigate to Services > Modbus > MQTT Gateway
 
Open routers WebUI and navigate to Services > Modbus > MQTT Gateway
   −
# Select Enable
+
#Select Enable
 
#Enter Host (copied from flespi connection settings without 'wss://' and port)
 
#Enter Host (copied from flespi connection settings without 'wss://' and port)
 
#Enter Username (Copied from flespi Connection settings generated token)
 
#Enter Username (Copied from flespi Connection settings generated token)
Line 64: Line 69:     
===Message format for MQTT publisher===
 
===Message format for MQTT publisher===
 +
----
 
Format is in text - heavier and slower, but less difficult to edit.
 
Format is in text - heavier and slower, but less difficult to edit.
 
{| class="wikitable"
 
{| class="wikitable"
Line 70: Line 76:  
|-
 
|-
 
|2. Cookie
 
|2. Cookie
|from '''0''' to '''2<sup>64</sup> -1'''
+
| from '''0''' to '''2<sup>64</sup> -1'''
 
|-
 
|-
 
|3. IP Type
 
|3. IP Type
 
|'''0''' - IPv4; '''1''' - IPv6; '''2''' - hostname
 
|'''0''' - IPv4; '''1''' - IPv6; '''2''' - hostname
 
|-
 
|-
|4. IP
+
| 4. IP
 
|IPv6 must be in full format (for example: '''2001:0db8:0000:0000:0000:8a2e:0370:7334''')
 
|IPv6 must be in full format (for example: '''2001:0db8:0000:0000:0000:8a2e:0370:7334''')
 
|-
 
|-
|5. Port
+
| 5. Port
 
|Port number (for example: '''502''')
 
|Port number (for example: '''502''')
 
|-
 
|-
| 6. Timeout in seconds (time to wait for response)
+
|6. Timeout in seconds (time to wait for response)
 
|from '''1''' to '''999'''
 
|from '''1''' to '''999'''
 
|-
 
|-
Line 102: Line 108:     
====Examples====
 
====Examples====
 +
----
 
{| class="wikitable"
 
{| class="wikitable"
| Setting relay (on) (Relay address is 202, which means 'Number of first register will be 203)
+
|Setting relay (on) (Relay address is 202, which means 'Number of first register will be 203)
 
|'''0 65432 0 192.168.1.1 502 5 1 6 203 1'''
 
|'''0 65432 0 192.168.1.1 502 5 1 6 203 1'''
 
|-
 
|-
Line 110: Line 117:  
|}
 
|}
   −
===Testing MQTT Publisher and Subscriber on flespi.io===
+
=== Testing MQTT Publisher and Subscriber on flespi.io ===
 +
----
 
Login and navigate to MQTT Board on https://flespi.io
 
Login and navigate to MQTT Board on https://flespi.io
    
Add a subscriber:
 
Add a subscriber:
   −
#Press '''''<nowiki/>'+'''''' button on the top right corner
+
# Press '''''<nowiki/>'+'''''' button on the top right corner
#Select '''''<nowiki/>'Subscriber''''''
+
# Select '''''<nowiki/>'Subscriber''''''
 
#In the topic field enter '''''<nowiki/>'response''''''
 
#In the topic field enter '''''<nowiki/>'response''''''
 
#Press '''''<nowiki/>'Subscribe'''''' button
 
#Press '''''<nowiki/>'Subscribe'''''' button
Line 124: Line 132:  
Add a Publisher:
 
Add a Publisher:
   −
#Press '''''<nowiki/>'+'''''' button on the top right corner
+
# Press '''''<nowiki/>'+'''''' button on the top right corner
 
#Select '''''<nowiki/>'Publisher''''''
 
#Select '''''<nowiki/>'Publisher''''''
 
#In the topic field enter '''''<nowiki/>'request''''''
 
#In the topic field enter '''''<nowiki/>'request''''''
Line 139: Line 147:  
''This Means that MQTT Gateway on Modbus TCP Master router is working correctly and Modbus TCP Slave receives requests.''
 
''This Means that MQTT Gateway on Modbus TCP Master router is working correctly and Modbus TCP Slave receives requests.''
   −
==Using RUT240 router as broker==
+
==Using RUT240 router as broker ==
    
[[File:Networking Topology MQTT MODBUS RUTbroker configuration v1.png|987x987px]]
 
[[File:Networking Topology MQTT MODBUS RUTbroker configuration v1.png|987x987px]]
   −
=== Configuring Modbus TCP Master, MQTT Gateway MQTT Broker on RUT240 and MQTT Publisher/Subscriber on PC ===
+
===Configuring Modbus TCP Master, MQTT Gateway MQTT Broker on RUT240 and MQTT Publisher/Subscriber on PC===
 +
----
 
''Same configuration will be used for Modbus TCP Master and Slave RUT955 routers as in previous example, only settings in Modbus TCP Master router RUT955 will be changed to match MQTT Broker on RUT240 router''
 
''Same configuration will be used for Modbus TCP Master and Slave RUT955 routers as in previous example, only settings in Modbus TCP Master router RUT955 will be changed to match MQTT Broker on RUT240 router''
    
Navigate to '''Services > Modbus > MQTT Gateway'''
 
Navigate to '''Services > Modbus > MQTT Gateway'''
   −
# '''Enable'''  
+
#'''Enable'''
# Host: '''Enter Public IP address of MQTT Broker (RUT240)'''
+
#Host: '''Enter Public IP address of MQTT Broker (RUT240)'''
 
# Username: '''N/A'''
 
# Username: '''N/A'''
# Password: '''N/A'''
+
#Password: '''N/A'''
# Press '''Save & Apply'''
+
#Press '''Save & Apply'''
    
[[File:Networking MQTT Modbus MQTT gateway config v1.png|border|1130x1130px]]
 
[[File:Networking MQTT Modbus MQTT gateway config v1.png|border|1130x1130px]]
   −
=== Configuring RUT240 MQTT Broker ===
+
===Configuring RUT240 MQTT Broker ===
 
+
----
    
Navigate to '''Services > MQTT > Broker'''
 
Navigate to '''Services > MQTT > Broker'''
   −
# Select '''Enable'''
+
#Select '''Enable'''
# Check '''Enable Remote Access'''
+
#Check '''Enable Remote Access'''
# Press '''Save & Apply'''
+
#Press '''Save & Apply'''
    
[[File:Networking MQTT Modbus MQTT Broker RUTos config v1.png|border|1133x1133px]]
 
[[File:Networking MQTT Modbus MQTT Broker RUTos config v1.png|border|1133x1133px]]
   −
=== Testing MQTT Gateway ===
+
===Testing MQTT Gateway===
 
+
----
    
For testing purposes, two terminal windows will be used on the same PC.  
 
For testing purposes, two terminal windows will be used on the same PC.  
Line 174: Line 183:  
''To get Ubuntu terminal  on Windows 10/11, refer to the following link for instructions:'' https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0
 
''To get Ubuntu terminal  on Windows 10/11, refer to the following link for instructions:'' https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0
   −
* Open first terminal, which will act as '''Subscriber'''. Type in:  
+
*Open first terminal, which will act as '''Subscriber'''. Type in:
    
<blockquote>''mosquito_sub -h [Host_address] -p [Port] -t [Topic]''</blockquote>[[File:Networking MQTT Modbus Subscriber in terminal v1.png]]
 
<blockquote>''mosquito_sub -h [Host_address] -p [Port] -t [Topic]''</blockquote>[[File:Networking MQTT Modbus Subscriber in terminal v1.png]]
Line 182: Line 191:  
<blockquote>''mosquito_pub -h [Host] -h [Host_address] -p [Port] -m [‘Message’] -t [Topic]''</blockquote>[[File:Networking MQTT Modbus Publisher testing v1.png]]
 
<blockquote>''mosquito_pub -h [Host] -h [Host_address] -p [Port] -m [‘Message’] -t [Topic]''</blockquote>[[File:Networking MQTT Modbus Publisher testing v1.png]]
   −
* On the first window - '''Subscriber''', a response should appear
+
*On the first window - '''Subscriber''', a response should appear
    
[[File:Networking MQTT Modbus Subscriber response ubuntu v1.png]]
 
[[File:Networking MQTT Modbus Subscriber response ubuntu v1.png]]

Navigation menu