This article is going to cover shortly how to install Mosquitto MQTT broker On Ubuntu 16.04 using apt-get. As for other operating systems and other Linux distros as well, you can find the installation guides on the Mosquitto website.

Install Mosquitto MQTT Broker on Ubuntu 16.04 LTS - Mosquitto MQTT Broker  Logo

Mosquitto MQTT Broker

1. Add the Mosquitto-dev PPA to repositories list

To install Mosquitto MQTT Broker On Ubuntu 16.04, we will need to add the Mosquitto PPA repository first. And we can do that simply by running the below command:

If you’re behind a proxy, you can try to add -E parameter to the command

2. Update Package Repository

The next is to update your package repository

3. Install Mosquitto MQTT Broker on Ubuntu 16.04

To install the broker, we can execute the below command:

Next, we will install mosquitto-clients package which is a Mosquittoclient or Mosquitto CLI, allows us to communicate the Mosquitto broker for different purposes such as: debugging, testing, etc

4. Basic about Mosquitto MQTT Broker

4.1. Starting the Mosquitto broker

4.2. Stopping the broker

4.3. Checking status of the broker

4.4. Configuration

The configuration file of the Mosquitto broker is located at: /etc/mosquitto/mosquitto.conf

The default TCP port of the broker is 1883 which is used for the ‘mqtt’ scheme and the port 8883 is used by default for the ‘mqtts’ scheme.

If you want to access the broker from the outside, make sure those ports are not blocked by your firewall.

5. Testing The Mosquitto MQTT Broker

We have finished the installation, and in this section we will verify whether the Mosquitto works or not. We will publish messages and subscribe on the topic: hellomqtt/test.

5.1. Subscribe on the topic: hellomqtt/topic

Open a new terminal (we call it terminal #1) and execute the command:

After the above command, the terminal will block and listen for the messages on the topic “hellomqtt/topic”

5.2. Publish on the topic: hellomqtt/topic

Open a new terminal (we call it terminal #2) and publish several messages to the “hellomqtt/topic”

The output on the terminal #2 will be similar to:

Back to the terminal #1, we will see the “Hello world” message appeared.

6. Summary

We have learned how to install Mosquitto MQTT Broker on Ubuntu 16.04 and some basic operations and configurations as well. More advanced usages and configuration will come in future posts.

Below are other related posts:

Apache Kafka Connect MQTT Source Tutorial

0 0 vote
Article Rating