Eclipse Mosquitto is an open-source message broker (EPL/EDL licensed) that supports MQTT versions 5.0, 3.1.1, and 3.1. The MQTT protocol uses a publish/subscribe method to deliver a lightweight messaging method. This makes it outstanding for Internet of Things (IoT) communications, as with low-power sensors or mobile devices like phones, embedded computers, and microcontrollers. Mosquitto is a lightweight operating system that may be employed on many devices, from low-power single-board computers to full-fledged servers. This tutorial guides you on how to install MQTT Mosquitto Broker version 2.0, MQTT version v5.0, on your windows machine. You can follow this tutorial on any windows machine.
Refer this article for the introduction of MQTT Mosquitto Broker.
Download MQTT Mosquitto Broker
To start with the installation, first download the MQTT Mosquitto broker from the official website. Click on the download link below:
You can choose 32 bit or 64 bit based on your windows computer.
After downloading the installer, you get a .exe file. After you run the .exe file, if you get a message from the Windows PC Protector, click Run anyway.
Mosquitto Broker Setup
Finish your setup by selecting the preferred location for your mosquitto broker on your windows machine.
To complete your broker installation, open the Command Prompt (run as Administrator).
Start < Command Prompt ( Right click) < Run as Administrator
Mosquitto Broker Installation
Now, navigate to your broker installation location on the Command Prompt.
Run the following command to install the mosquitto on your machine.
mosquitto install
Probably, you will get a message that the mosquitto broker is already installed on your windows machine. Then, run the command,
net mosquitto start
After you run this command, the mosquitto broker will start. You will get a message that the mosquitto broker has started successfully. This means that, you have successfully installed the mosquitto MQTT broker on your windows machine.
Publisher and Subscriber on windows: Testing Mosquitto Broker
In order to test the mosquitto broker installation, we will publish some messages on a topic and subscribe the topic. First of all, we will create a topic, and we call it as “Test“. You can name this as whatever you want. Basically, we will send some messages on the topic from the publisher to the subscriber. We need to open 2 terminals for this, one terminal sends the messages on the topic ( Publisher), and the other terminal receives the messages ( Subscriber ). Here, terminal is the command Prompt run as administrator.
Run this command to subscribe the topic,
mosquitto_sub -d -t Test
Open another terminal to publish the message to the topic, and run this command,
mosquitto_pub -d -t Test -m “hello world”
Here the payload message is “hello world”, -m is the message flage, -t is the topic flag, -d is the daemon, which runs the mosquitto in the background.
Mosquitto Broker on a different Port
Basically, by default the MQTT uses the port 1883. If you are want to install the broker on a different port, you have to change the listening port.
To change this, go to your mosquitto folder and open mosquitto.conf file with Notepad++, and add the listener port
port 1889
With these changes, you have successfully installed the broker on a different port.