If Mosquitto is not yet installed, refer to https://mosquitto.org/download/ for installation instructions.
With the Mosquitto PPA added to the repository lists, install the Mosquitto broker and helper clients with:
1 2 |
sudo apt install mosquitto mosquitto-clients |
Before starting a client program, ensure that the Mosquitto Broker is installed and running with:
1 2 |
pgrep mosquitto |
If the Mosquitto Broker is active, the output will be the PID number associated with the Mosquitto daemon. For example:
1 2 3 |
my@cpu:~$ pgrep mosquitto 5332 |
If the pgrep
command yields no output, start Mosquitto with:
1 2 |
mosquitto -v |
The -v
flag enables Verbose mode. Making it easier to troubleshoot connections to the broker.
If Verbose mode is not desired, the Mosquitto broker can be started in Daemon mode by passing parameter -d
.
Daemon mode runs the Mosquitto broker in the background, freeing up a terminal for other purposes.
1 2 |
mosquitto -d |
Testing The Connection
The data being published to the Mosquitto Broker can be viewed with:
1 2 |
mosquitto_sub -t '#' -v |
To publish a message, in another terminal:
1 2 |
mosquitto_pub -t 'TOPIC/SUB' -m 'MESSAGE' |
That Is It
If a connection was successfully established with the local Mosquitto broker, you are ready to continue by programming clients to communicate through the broker.
Check out the following guides on programming MQTT clients: