Changes

249 bytes added ,  10:31, 1 December 2017
Line 79: Line 79:  
  $ sudo apt-get install mosquitto mosquitto-clients
 
  $ sudo apt-get install mosquitto mosquitto-clients
   −
Now you can use set up Brokers and Clients on your PC. Continuing from the example above, lets say we want to monitor the router's '''signal strength''' and '''up time''' values. In order to do that we'll need to subscribe to the topics '''router/<SERIAL>/signal''' and '''router/<SERIAL>/uptime''' using the '''mosquitto_sub''' command. Open a second Terminal window and enter this command:
+
Now you can use set up Brokers and Clients on your PC. In order to Publish commands and Subscribe to topics on a RUT router, you'll need to know the router's '''Serial Number'''. You can find your router's serial number in the '''Status → Device''' section of the router's WebUI. Or you can subscribe to the topic '''router/id''' and publish the message '''id''' to the topic '''router/get'''. To do so, enter these commands in separate Terminal windows:
   −
  $ mosquitto_sub -h 192.168.1.1 -p 1833 -u user -P pass -t router/<SERIAL>/signal -t router/<SERIAL>/uptime
+
'''Subscribe:'''
 +
  $ mosquitto_sub -h 192.168.1.1 -p 1833 -u user -P pass -t router/id
   −
'''-h''' indicates the host (the Broker's IP address) which, continuing from the example above, is '''192.168.1.1'''. Replace this value with your router's LAN IP address or, if you're using MQTT remotely, your WAN IP address.
+
'''Publish:'''
 +
$ mosquitto_pub -h 192.168.1.1 -p 1833 -u user -P pass -t router/get -m id
   −
'''-p''' indicates the port used for connection to the Broker. Replace it with the port number that you specified in the Broker configuration.
     −
'''-u''' and '''-P''' specify the username and password. If the Broker doesn't require authentication, these values aren't mandatory. Else replace them with the log in information of your Broker.  
+
[[Image:Configuration examples mqtt router id v2.png]]
   −
Lastly, '''-t''' specifies the '''topics''' that you want to subscribe to, in this case it router/<SERIAL>/signal router/<SERIAL>/uptime. Replace '''<SERIAL>''' with your router's serial number. You can find your router's serial number in the '''Status → Device''' section of the router's WebUI. Or you can first subscribe to the topic '''router/id''' and publish the message '''id''' to the topic '''router/get'''. The full command would look like this:
     −
$ mosquitto_sub -h 192.168.1.1 -p 1833 -u user -P pass -t router/id
+
'''mosquitto_sub''' command is used to subscribe to a certain topic(s) and '''mosquitto_pub''' command is used to publish messages to specified topics. '''-m''' defines the message that you're publishing
   −
To publish a message asking the router for it's serial number, or '''id''', use this command:
+
'''-h''' indicates the host (the Broker's IP address) which, continuing from the example above, is '''192.168.1.1'''. Replace this value with your router's LAN IP address or, if you're using MQTT remotely, your WAN IP address.
   −
$ mosquitto_pub -h 192.168.1.1 -p 1833 -u user -P pass -t router/get -m id
+
'''-p''' indicates the port used for connection to the Broker. Replace it with the port number that you specified in the Broker configuration.
   −
The '''mosquitto_pub''' command is used to publish messages to specified topics. '''-m''' defines the message that you're publishing. Again, replace the values given with the ones in your configuration. The whole exchange is presented in the picture below:
+
'''-u''' and '''-P''' specify the username and password. If the Broker doesn't require authentication, these values aren't mandatory. Else replace them with the log in information of your Broker.  
    +
'''-t''' specifies the '''topics''' that you subscribe or publish to.
 +
 +
Now that we have the router's serial number we can start publishing messages and receiving responses containing the router's system parameter values. Lets say we want to monitor the router's '''signal strength''' and '''up time''' values. In order to do that we'll need to subscribe to the topics '''router/<SERIAL>/signal''' and '''router/<SERIAL>/uptime''' using the '''mosquitto_sub''' command. Again, replace the values given in the commands below with the ones in your configuration:
    +
'''Subscribe:'''
 +
$ mosquitto_sub -h 192.168.1.1 -p 1833 -u user -P pass -t router/<SERIAL>/signal -t router/<SERIAL>/uptime
   −
[[Image:Configuration examples mqtt router id.png]]
+
'''Publish:'''
 +
$ mosquitto_pub -h 192.168.1.1 -p 1833 -u user -P pass -t router/get -m signal
 +
$ mosquitto_pub -h 192.168.1.1 -p 1833 -u user -P pass -t router/get -m uptime

Navigation menu