Skip to main content
Skip table of contents

Setting Up an MQTT Broker on Linux using Mosquitto

For information on how to set up an MQTT broker on Windows using Mosquitto, please read our help article Setting Up the MQTT Broker on Windows using Mosquitto.

Getting Started

  1. Installing Mosquitto

    • Start by updating your package list to ensure you have the latest repository. To do this, open a terminal and enter the following command:
      sudo apt update

    • Next, install the Mosquitto broker and the Mosquitto Clients by entering the following command:
      sudo apt install mosquitto mosquitto-clients

  2. Configuring the MQTT Broker

    • To configure the Mosquitto broker, edit the Mosquitto configuration file:
      sudo nano /etc/mosquitto/mosquitto.conf

    • The following image shows an example configuration:

image-20240906-221021.png
  • Make sure to enter the following commands:
    listener 1883 (your IP address)
    allow_anonymous true

NOTE: To check the IP address of your Linux machine, enter the following command in the terminal:
ifconfig

The following image shows the output of the command. Use the inet IP address shown in your mosquitto.conf file.

image-20240906-221539.png
  1. Start and Enable Mosquitto Service:

    • Enter the following commands in the terminal to start and enable the Mosquitto Service.
      sudo systemctl start mosquitto
      sudo systemctl enable mosquitto

  2. Test the broker by publishing and subscribing to a test topic using the ZeroKey Dashboard:

    • Open the terminal and enter the following command:
      mosquitto sub -h [ip address from the mosquitto.conf file] -t "test"

    • Navigate to the ZeroKey Dashboard.

    • In the Integration tab, select the MQTT Settings, then click the + Add Connection button.

    • Under Host*, enter the IP address of the broker (Linux machine).

    • Under Port*, enter the port number 1883.

    • Under the Topic Title*, enter the same name as the broker’s topic. In this example, we are using topic named test.

    • Then, under Filter Template, select what data you wish to receive and click the Submit button.

image-20240906-223024.png
  • Upon successful connection, you will see the feedback in the MQTT Settings section, along with the Connect State of the MQTT connection. On the right, click the blue pencil icon to edit a connection and the red bin icon to delete it.

image-20240906-225802.png

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.