Setting up MQTT Mosquitto broker in Ubuntu Linux
1. Login to Ubuntu Linux with root privileges ( sudo )
2. Add the mosquitto repository by given below commands
1
2
| $sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa $sudo apt-get update |
3. Execute the given below command to install the Mosquitto broker package
1
| $ sudo apt-get install mosquitto |
4. Install Mosquitto developer libraries to develop MQTT clients
1
| sudo apt-get install libmosquitto-dev |
5. Execute the given below command to install Mosquitto client packages
1
| $ sudo apt-get install mosquitto-clients |
6. Ensure that Mosquitto broker is running
1
| $ sudo service mosquitto status |
For the above command, expected result is
mosquitto start/running, process 8288
where 8288 is the process id and will vary from machine to machine
7. Testing
Open a terminal and issue the given below command to subscribe the topic “mqtt”
1
| $mosquitto_sub -h localhost -t "mqtt" - v |
Open another terminal and issue the given below command to publish message to the topic “mqtt”
1
| $mosquitto_pub -h localhost -t "mqtt" -m "Hello MQTT" |
Now the message “Hello MQTT” will be displayed in the first terminal where the topic “mqtt” is subscribed.