Jump to content

Monitoring via MQTT: Difference between revisions

No edit summary
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Router monitoring via MQTT Linux guide applies to TRB devices and to RUT, TCR routers.
Router monitoring via MQTT Linux guide applies to TRB gateways and to RUT routers.
==Introduction==
==Introduction==


'''MQTT (MQ Telemetry Transport or Message Queue Telemetry Transport)''' is an ISO standard (ISO/IEC PRF 20922) publish-subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker.  
'''MQTT (MQ Telemetry Transport or Message Queue Telemetry Transport)''' is an ISO standard (ISO/IEC PRF 20922) publish-subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker.  


This article provides a guide on how to configure and use a basic MQTT setup on TRB devices and on RUT, TCR routers.
This article provides a guide on how to configure and use a basic MQTT setup on TRB gateways and on RUT routers.


==How MQTT works==
==How MQTT works==
In general an MQTT connection takes place between two Clients and a Broker. A TRB device and RUT/TCR router can be Broker, Client or both. The MQTT Publisher(Client) present in TRB devices and RUT/TCR routers subscribes to two topics by default: '''<TYPE>/get''' and '''get/<SERIAL>/command'''. Where '''<TYPE>''' is device type, for RUT/TCR routers type is '''router''' and for TRB devices type is '''device'''. Parameter  '''<SERIAL>''' is the router's serial number. When a third party client connects to the Broker, it sends the message '''id''' to the the topic '''<TYPE>/get'''. The publisher then sends a response containing its serial number to the topic '''<TYPE>/id'''. Now that the Client knows the router's or device's serial number it can ask for values of various parameters by sending requests to the topic '''<TYPE>/<SERIAL>/parameter_name'''. The MQTT Publisher can send responses containing values of these system parameters, if device supports that parameter:
In general an MQTT connection takes place between two Clients and a Broker. A TRB device and RUT/TCR router can be Broker, Client or both. The MQTT Publisher(Client) present in TRB devices and RUT/TCR routers subscribes to two topics by default: '''<TYPE>/get''' and '''get/<SERIAL>/command'''. Where '''<TYPE>''' is the device type, for RUT/TCR routers type is '''router''' and for TRB devices type is '''device'''. Parameter  '''<SERIAL>''' is the router's serial number. When a third-party client connects to the Broker, it sends the message '''id''' to the the topic '''<TYPE>/get'''. The publisher then sends a response containing its serial number to the topic '''<TYPE>/id'''. Now that the Client knows the router's or device's serial number it can ask for values of various parameters by sending requests to the topic '''<TYPE>/<SERIAL>/parameter_name'''.
 
<br>There is also an option to use '''prefix''' instead of the default topic structure:
 
[[File:Monitoring_via_mqtt_publisher_prefix.png|border|class=tlt-border]]
* Publisher
<TYPE>/get with prefix -> '''<PREFIX>/get'''
* Subscriber
<TYPE>/<SERIAL>/parameter_name with prefix -> '''<PREFIX>/parameter_name'''
 
The MQTT Publisher can send responses containing values of the system parameters if the device supports that parameter:


{| class="wikitable"
{| class="wikitable"
Line 18: Line 28:
! style="text-align: left; vertical-align: top;" | id
! style="text-align: left; vertical-align: top;" | id
| style="text-align: left; vertical-align: top;" | Modem IMEI
| style="text-align: left; vertical-align: top;" | Modem IMEI
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB2, TRB5, OTD, RUT1, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | temperature
! style="text-align: left; vertical-align: top;" | temperature
| style="text-align: left; vertical-align: top;" | Temperature of the module in 0.1 degrees Celsius
| style="text-align: left; vertical-align: top;" | Temperature of the module in 0.1 degrees Celsius
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB2, TRB5, OTD, RUT1, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | operator
! style="text-align: left; vertical-align: top;" | operator
| style="text-align: left; vertical-align: top;" | Current operator’s name
| style="text-align: left; vertical-align: top;" | Current operator’s name
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | signal
! style="text-align: left; vertical-align: top;" | signal
| style="text-align: left; vertical-align: top;" | Signal strength in dBm
| style="text-align: left; vertical-align: top;" | Signal strength in dBm
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | network
! style="text-align: left; vertical-align: top;" | network
| style="text-align: left; vertical-align: top;" | Network state
| style="text-align: left; vertical-align: top;" | Network state
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | connection
! style="text-align: left; vertical-align: top;" | connection
| style="text-align: left; vertical-align: top;" | Current connection type (2G, 3G, 4G)
| style="text-align: left; vertical-align: top;" | Current connection type (2G, 3G, 4G)
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | wan
! style="text-align: left; vertical-align: top;" | wan
| style="text-align: left; vertical-align: top;" | WAN IP address
| style="text-align: left; vertical-align: top;" | WAN IP address
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUT1, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | uptime
! style="text-align: left; vertical-align: top;" | uptime
| style="text-align: left; vertical-align: top;" | System uptime in seconds
| style="text-align: left; vertical-align: top;" | System uptime in seconds
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUT1, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | name
! style="text-align: left; vertical-align: top;" | name
| style="text-align: left; vertical-align: top;" | Device's device code
| style="text-align: left; vertical-align: top;" | Device's device code
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TCR1, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, RUT1, TRB1, TRB2, TRB5, OTD, RUT1, RUTM, RUTC
|-
|-
! style="text-align: left; vertical-align: top;" | digital1
! style="text-align: left; vertical-align: top;" | digital1
Line 62: Line 72:
! style="text-align: left; vertical-align: top;" | analog
! style="text-align: left; vertical-align: top;" | analog
| style="text-align: left; vertical-align: top;" | Value of analog
| style="text-align: left; vertical-align: top;" | Value of analog
| style="text-align: left; vertical-align: top;" | RUT9, TRB2
| style="text-align: left; vertical-align: top;" | RUT9, TRB2, TRB141
|-
|-
! style="text-align: left; vertical-align: top;" | pin2
! style="text-align: left; vertical-align: top;" | pin2
Line 70: Line 80:
! style="text-align: left; vertical-align: top;" | pin3
! style="text-align: left; vertical-align: top;" | pin3
| style="text-align: left; vertical-align: top;" | Value of 3's pin state
| style="text-align: left; vertical-align: top;" | Value of 3's pin state
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT1, RUT2, RUT9, RUTX, RUT3, TRB1, TRB2, TRB5, RUTM
|-
|-
! style="text-align: left; vertical-align: top;" | pin4
! style="text-align: left; vertical-align: top;" | pin4
| style="text-align: left; vertical-align: top;" | Value of 4's pin state
| style="text-align: left; vertical-align: top;" | Value of 4's pin state
| style="text-align: left; vertical-align: top;" | RUT2, RUT9, RUTX, RUT3, TRB1, TRB2
| style="text-align: left; vertical-align: top;" | RUT1, RUT2, RUT9, RUTX, RUT3, TRB1, TRB2, TRB5, RUTM
|-
|-
|}
|}
Line 83: Line 93:
[[File:Configuration examples mqtt scheme v2.jpg|border|class=tlt-border]]
[[File:Configuration examples mqtt scheme v2.jpg|border|class=tlt-border]]


It should also be noted that, according to the MQTT protocol, topic names are case-sensitive. For instance, topic ''router'' is not the same as topic ''RoUtEr''.
It should also be noted that, according to the MQTT protocol, topic names are '''case-sensitive'''. For instance, topic '''''router''''' is not the same as topic '''''ROUTER'''''.


==Configuring the device==
==Configuring the device==


This section will provide an explanation on how to configure an MQTT Broker and MQTT Publisher on a TRB devices and on RUT/TCR routers.
This section will provide an explanation on how to configure an MQTT Broker and MQTT Publisher on a TRB gateways and on RUT routers.


===Broker===
===Broker===
----
----
Basic (not counting Security, Bridge and Miscellaneous Broker settings) Broker configuration only contains three fields. Make sure to '''Enable''' the Broker and specify a '''Port''' for connection to the Broker. ''' Enable Remote Access''' if you wish to connect to your router remotely (via WAN). Although in this case your router would need to have a Public IP address. In image below is presented how to configure RUT9xx routers:
Basic (not counting Security, Bridge and Miscellaneous Broker settings) Broker configuration only contains three fields. Make sure to '''Enable''' the Broker and specify a '''Port''' for connection to the Broker. ''' Enable Remote Access''' if you wish to connect to your router remotely (via WAN). Although in this case your router would need to have a Public IP address. In image below is presented how to configure routers:
   
   
[[Image:Configuration examples mqtt broker.png|border|class=tlt-border]]
[[File:Monitoring_via_mqtt_enable.png|border|class=tlt-border|500x167]]




Configuration for a TRB device and a RUT/TCR router looks like this:
If you want to access the broker without password or ACL file, then you need to enable "Allow anonymous" option in Broker settings -> Miscellaneous section:


[[Image:Configuration_examples_publisher_new_design.png|border|class=tlt-border]]
[[File:Monitoring_via_mqtt_broker_misc_anon.png|border|class=tlt-border|500x167]]


===Publisher===
===Publisher===
----
----


Publisher configuration is similar in its simplicity to the Broker configuration. Make sure to '''Enable''' the Publisher and specify a '''Port''' for connection to a Broker. If you plan on using the router's Broker, specify the same port as the one in the Broker Settings section. '''Hostname''' is the Broker's host name or IP address. If you're using the router's Broker, specify your router's LAN IP address. '''Username''' and '''Password''' are optional and depend on the type of security (if any) that the Broker uses. In image below is presented how configure RUT9xx routers:
Publisher configuration is similar in its simplicity to the Broker configuration. Make sure to '''Enable''' the Publisher and specify a '''Port''' for connection to a Broker. If you plan on using the router's Broker, specify the same port as the one in the Broker Settings section. '''Hostname''' is the Broker's host name or IP address. If you're using the router's Broker, specify your router's LAN IP address. '''Username''' and '''Password''' are optional and depend on the type of security (if any) that the Broker uses. In image below is presented how configure TRB gateways and RUT routers:


[[Image:Configuration examples mqtt publisher.png|border|class=tlt-border]]
[[File:Monitoring_via_mqtt_publisher_general.png|border|class=tlt-border]]


Configuration for a TRB device and a RUT/TCR router looks like this:
[[Image:Configuration examples mqtt publisher_new_design.png.png|border|class=tlt-border]]


<b>NOTE</b>: If you are configuring a TRB device, default hostname is 192.168.2.1.
<b>NOTE</b>: If you are configuring a TRB device, default hostname is 192.168.2.1.
Line 135: Line 141:
In image below is presented example of how to get RUT router serial number:
In image below is presented example of how to get RUT router serial number:


[[Image:Configuration examples mqtt router id v7.png|border|class=tlt-border]]
[[File:Configuration examples mqtt router id new 1.png|border|class=tlt-border]]




Line 159: Line 165:
In example below you can see how to subscribe and publish to the topics '''signal strength''' and '''uptime''' on RUT/TCR routers:
In example below you can see how to subscribe and publish to the topics '''signal strength''' and '''uptime''' on RUT/TCR routers:


[[File:Configuration examples mqtt subscribe publish v5.png|1150px]]
[[File:Configuration examples mqtt subscribe publish new 2.png|1100px|border|class=tlt-border]]
 
==External links==
https://mosquitto.org/ - Eclipse Mosquitto official website
 
[[Category:Router control and monitoring]]