Installing MQTT Broker on Ubuntu 20.04

If you remember, last time we discussed MQTT, What is MQTT? Why it used and where it used. So now, I think probably you are going to use MQTT. That’s why you’re reading this post.

If you need some introduction to MQTT, please check my previous blog post.

Then let’s install MQTT on Ubuntu 20.04.

In this post,

Note: To install MQTT on Raspberry Pi is also pretty similar. 

Installing MQTT on Ubuntu 20.04

Step 1 : Update Ubuntu package list and install the latest Mosquitto broker available from it.

To update ubuntu package list and install MQTT broker, use the following commands

$ sudo apt update                                                                                                    
$ sudo apt install mosquitto

Install MQTT clients

To install MQTT clients tools, use the following command.

                    $ sudo apt install mosquitto-clients                                                                            

Test MQTT broker and client

To test MQTT Broker, we can use the 2 terminals and use 1 terminal to subscribe to a topic and from the other terminal we can publish something to that topic and check if we received the message.

First let’s subscribe to a topin with terminal 1. For that use the following command to subscribe to the topic “ test”.

                    $ mosquitto_sub -t “test”                                                                                            

In above command, mosquitto_sub is to subscribe to a client we installed from the previous command. From -t, we specify to subscribe to the following topic.

Now let’s take the 2nd terminal to publish data to topic “test”. For that use the following command.

                    $ mosquitto_pub -m “Test Message from client” -t “test”                                            

In the above command, mosquitto_pub is a subscribe client from the previously installed mqtt client. -m additional parameter is followed with the publishing message and -t parameter is followed with the mqtt topic.

Do you know what this means? This means now MQTT broker and client works perfectly on your Ubuntu OS. (or in raspberry pi if installed).

So now, if your computer is connected to WiFi, then you can publish messages from any device to your MQTT broker using your IP address. Also you can subscribe to topics using other devices.

Well, then good luck with your projects using MQTT. 

Do you have any issues with MQTT? Or related projects, just comment in below comments area.


***Please note that all of the content on this post was originally published on champlnx.blogspot.com. We have migrated these posts to www.champlnx.com for your convenience and continued access.

One Response

  1. I think that you should probably test your assertion that clients on the network will be able to communicate with the broker.
    The default installation is only available on localhost. In order to access by IP address and port 1883, a mosquitto config file is required.
    David

Leave a Reply

Your email address will not be published. Required fields are marked *