Skip to content

MQTT Testing

Fyzel edited this page Sep 8, 2018 · 2 revisions

In order to confirm that the MQTT configuration on the Raspberry Pi functions as expected, perform the following tasks.

  1. On the Local MQTT Broker, enable the logging all option in /etc/mosquitto/conf.d/default.config to troubleshoot the connection.

  2. Restart Mosquitto.

sudo service mosquitto stop && sudo service mosquitto start
  1. tail the Mosquitto log to trace the debugging messages.
sudo tail -f /var/log/mosquitto/mosquitto.log
  1. Connect a MQTT subscriber to the Local MQTT Broker. Specify the QOS as 2, the test topic, and the username and password.
mosquitto_sub -h localhost -p 1883 -q 2 -t "test" -u "weather-api-user" -P "secret"
  1. A test message can be queued to the Local MQTT Broker to confirm local communication.
mosquitto_pub -h localhost -p 1883 -t "test" -m "hello password protected world" -u "weather-api-user" -P "secret" -d

This will result in the message hello password protected world in the subscriber's output.

  1. The Remote MQTT Broker's connectivity can be confirmed by running mosquitto_sub on the remote server or installing mqtt-spy and connecting remotely.

There may be a slight delay between the bridged messages.

Clone this wiki locally