In this tutorial you will learn how to install the mosquitto MQTT broker (server) on Windows.
See the installing Mosquitto on Linux tutorial for how to install on a local Linux server and also a cloud server (AWS).
Installing The Mosquitto Broker on Windows
Note: The term server instead of broker as been adopted as of MQTT version 3.1.1
There are two possibilities:
- Quick Install
- Standard Install
Quick Windows Install
The problem with the standard install is that there are certain dependencies that need to be installed before you can do the mosquitto install.
This involves installing software and copying files from other installs into the Mosquitto install folder.
You should note that from version 1.5 on support for windows XP was dropped, so if you need to run mosquitto on XP the you need to use an older version.
The version will also run on Windows ,7,8 and 10. It doesn’t have web sockets support.
This tutorial cover the Install on XP and includes the download files
Quick Install Mosquitto v 1.5.8 and 1.6.9
This version of Mosquitto works with websockets.
Here is my download package for v2
Here is my download package (1.6.9)and includes the SSL files for encryption .
Here is my download package ( 1.5.8) and includes the SSL files for encryption .
Just unzip it go to the directory and run the broker manually as covered here.
Don’t forget to virus check it let me know if you have any problems with it.
Websockets on Windows Notes
Since mosquitto 1.5.1 websockets support has been enabled on the windows binary files.
However when using 1.5.1., 1.52 and 1.53 when you start mosquitto it appears to be listening on the websocket port but doesn’t allow connections.
mosquitto v 1.5.4 and above works with websockets.
Manual Install Windows
To install manually you will need to download the files from Eclipse. Here is the link.
As mentioned earlier the big problem with the Windows Install is that there are lots of dependencies that you also need to install or have installed.
From version 1.5.8 the install script lets you install mosquitto as a service.
When Mosquitto is installed as a service it starts automatically.
However this is not important for a test environment.
First you will need to download the Windows install files from here.
1. Double Click on the install script
2. Note the dependencies screen which tells you what additional files are required. The screen is note very clear
3. Select components check service to install as a service if you want mosquitto to start automatically when windows starts.
4. Choose a location it defaults to c:\program files\mosquitto.
You then need to copy the additional files to the install directory after the install again.
The additional files are
Note 1: You can obtain these files by installing openssl using the files from here or by downloading my package.
Note2: They are now included in the 1.5.8 install package.
Starting Mosquitto on Windows
To start the broker manually open a command prompt and go to the mosquitto install directory and type mosquitto.
You can also use various command line switches. Type
To start in verbose mode so that you can see console messages use the -v option:
Running Mosquitto as a Service -Update 22-12-2018 -Notes version 1.5.4 and below
On production environments you will need mosquitto to auto start on a reboot.
To start mosquitto as a service the usual use of the sc command didn’t work as seen from the screen shots below.
However a reader pointed out the power shell option which does work
Here is a screen shot of my attempts using sc command
Note you need to open the command prompt as administrator.
Installing Mosquitto as a Service using Power Shell
Open a power shell command prompt as administrator.
Change to the directory where you have installed mosquitto (mos154 below) and type:
Mosquitto is added but you don’t get any confirmation and it isn’t started but will start on reboot. However you can now start it manually.
Now open a normal command prompt again as administrator and type the commands:
sc query mosquitto sc start mosquitto sc query mosquitto
Testing The Install
To test it is running use command:
- netstat -a
You should see the Mosquitto broker running on port 1883 as shown in the screen shot above.
Another quick test is to try to start it twice in two different command prompts.
You should get an error message complaining about the port being in use.
The Mosquitto.conf File
The configuration file (mosquitto.conf) that comes with the install is completely commented out, and the MQTT broker doesn’t need it to start.
However when Mosquitto runs as a service it uses this configuration file. .
Instead create a blank file and add you entries to it using the commented out file as documentation.
If you enable logging in the mosquitto.conf file then when mosquitto runs it creates this file with restricted permissions, and locks the file while the broker is running.
If you stop the broker you can change the permissions on the file to access it.
Mosquitto 2..0.2 and above
Mosquitto v2 introduced some important changes that affect first time users in particular.
By default it requires authentication and doesn’t listen on a network address.
The following simple configuration file will make mosquitto start like previous versions:
listener 1883 allow_anonymous true
Stopping The Mosquitto Service
When testing it is better to start mosquitto manually from the command line. In order to do this you either need to use a different port than the running version or stop the running version.
I prefer to stop the running version and set it for manual start when working in a test environment. To Stop the service and set the start mode type services in the search bar (lower left) and select the services App.
Locate the mosquitto service and stop it. I set mine to manual mode when working in a test environment.
Running Multiple Mosquitto Brokers
You can configure a broker to listen on several ports, but to create multiple brokers with their own configurations then you will need to start multiple instances of mosquitto. See Quick Guide to the Mosquitto.conf file and this video on running multiple brokers.
Start mosquitto and listen on port 1883
mosquitto -p 1883
Start mosquitto and listen on port 1884
mosquitto -p 1884
Start mosquitto and use the mosquitti-2.conf file.
mosquitto -c c:\mosquitto\mosquitto-2.conf
Note: starting as a daemon (-d) is not supported on windows.
Mosquitto Client Scripts
The windows install includes the client scripts.
There is a simple subscriber client
and a publisher client
They are useful for some quick tests. See Using The Mosquitto_pub and Mosquitto_sub Client Tools- Examples
Common Questions and Answers
Q- What is the difference between a quick install and a standard manual install?
A- Using my install package you don’t need to install any other software as the package includes the necessary files. A standard manual install installs mosquitto as a service but a quick install doesn’t.
Q- I have Mosquitto broker installed on one Windows machine can I copy it to another machine?
A- If you have already installed Mosquitto on another windows machine e.g. XP and want to install it on another machine e.g. Windows 10 then you can just copy the directory containing the mosquitto files to the new machine.
I copied my windows XP install (32 bit) onto a windows 10 (64bit) machine and a Windows 7 machine and it worked OK.
You need to be aware of the versions as windows XP doesn’t support Mosquitto v 1.5 and above.
MQTTlens is also very useful for troubleshooting and quick testing. It is an add-on for the chrome browser.
It lets you publish and subscribe to topics using a web interface, and is much easier to use than the command line clients.
MQTT-Ping -Python Tool written by me that works like the traditional IP ping command tool.
MQTT v5 Support
Note: Starting will mosquitto version 1.6 mosquitto now supports MQTT v5.
If you are using MQTT with websockets and mosquittov2 then it has problems and you will may need to go back to 1.6.9 (email from Keith)
I have a web page client that uses Windows Sockets to connect and a C# program that connects using MQTT. If I connect using the C# program everything works fine. As soon as I connect using Windows Sockets to the broker the C# program stops being able to connect. No error messages appear on the server but eventually the C# client times out. If I restart the server, the MQTT client can connect. However, as soon as the Windows Sockets program connects the MQTT client is not able to connect.
I did a little research on this and apparently it is a known issue with version 2 of the mosquitto broker on Windows. The solution appears to be to use an older version, in my case 1.6.9. That works perfectly.
Anyway, I didn’t know if you knew this and if not, maybe it is something you might want to mention on your web site.
Here is the link that I found from the Eclipse website that explains it.
Mosquitto Configuration Tutorials
- Configuring and Testing MQTT Topic Restrictions
- Configuring Username and Password Authentication
- MQTT TLS Security – Mosquitto Broker Configuration
- Understanding and Configuring Bridging on Mosquitto
- Configure Mosquitto Bridge With SSL Encryption- Examples
Other Related Articles and Resources: