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 (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.
Video – How to Install Mosquitto Broker on Windows
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.
Install Steps
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.
5. Finish
You then need to copy the additional files to the install directory after the install again.
The additional files are
- libcrypto-1_1_x64.dll
- libssl-1_1_x64.dll
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
mosquitto -h
for help.
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 install
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.
See Quick Guide to The Mosquitto.conf File With Examples
Mosquitto Logging
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.
See Understanding and Configuring Logging on Mosquitto
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.
Examples:
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
mosquitto_sub
and a publisher client
mosquitto_pub
Use
mosquitto_sub –help
They are useful for some quick tests. See Using The Mosquitto_pub and Mosquitto_sub Client Tools- Examples
Video
How to install the Mosquitto Broker on Windows
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.
———————–
Other Tools
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.
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:
I want to install this silently on a Windows system but NOT install the service option. I have figured out that the /S switch will install it silently, when elevated with no UI, BUT….how do I deselect the service option? Is there a switch I can pass that will deselect that option.
Installing on a Windows 64 bit system using:
mosquitto-1.6.7-install-windows-x64.exe
TIA
KIWI
Hi
Not sure but if you download my files you can run them without doing an install. If you have installed it on another machine you can just copy over the files and you don’t need to do an install.
Other than that just install as normal and disable the service. I haven’t looked at it for a while but you can probably remove it as a service.
Rgds
Steve
Hi,
Hope u are well ..
I have a strange query bothering me.
I installed the way you guided .
When on cmd i typed mosquitto -v ,
I got issue that only one usage of each socket packet is normally permitted.
Then i tried to find the core error, ended up in changing port number to 1884 in both inbound and outbound rules in firewall.
But that didnt resolved my issue ..
Then i commented out port number line in mosquitto.cong and changed it to 1884.
Now issue has resolved and showing
Opening ipv6/ipv4 listen socket on 1883 ..
I am confused .. why showing me 1883 though i have changed it to 1884 ..
I suspect that you have two instances of mosquitto running. When you install on windows or linux the install script installs the broker to start automatically.
So now if you start mosquitto from the command line it fails as the broker is already using that port which is why doing
mosquitto -v -p 1884 will work.
You need to check using netstat -a
Additionally when changing the conf file this will only work if you tell mosquitto to use it using
mosquitto -c mosquitto.conf.
The install script sets this automatically.
Rgds
Steve
I have successfully installed mosquitto and it is running/listening. I installed this so I can use another Windows program called IOT Link. End result will be to link Home Assistant with EventGhost. Anyhow, IOT Link is asking for MQTT credentials… How do I set credentials in mosquitto?
Thank you for the instructions!
Hi
I think this should help
http://www.steves-internet-guide.com/mqtt-username-password-example/
rgds
Steve
Thank you! However, mosquitto will not restart after updating the config file.
Hi
What message do you get? and what does the config file look like
rgds
Steve
Services error message:
“The MB service on Local Comp started and then stopped. Some services stop automatically if they are not in use by other services or programs.”
M.conf:
# Default listener
port 1883
# Extra listeners
listener 1884
# Security
allow_anonymous false
# Default authentication and topic access control
password_file “C:\Program Files\mosquitto\pass.txt”
Check that no other instance of mosquitto is running using the same ports.
rgds
Steve
Discovered the issue, thanks to a post in mosquitto github… Path to password file needs to be set w/o quotes. For those keeping the file in the Programs Files folder, you’ll need to identify it as…
C:\Progra~1\mosquitto\[password-file.txt]
Hi Steve,
how can I stop and restart the mosquitto servie on windows 10 ?
I’m assuming it is running as a service. If so you can use the services admin panel to stop it. If you started it manually the ctrl+C
rgds
Steve
Hi Steve
Never mind. I figured out. It works.
Best Regards,
Victor
I have installed mosquitto 1.6.9 in windows 7.
After running the moqsuitto server it is showing as mosquitto version 1.4.9. Does it support MQTT5.0.
Hi
Not that version. Don’t see why it is showing as 1.4.9 when you have installed 1.6.9.
Try the install again or download the files from the site and use those.
Rgds
Steve
Hi Steve,
Thanks for the quick reply.
I reinstalled 1.6.9 windows 32 bit version which is latest version(Build date is 4-march 2020). I downloaded from https://mosquitto.org/files/binary/win32/ link.
I ran the broker using the command mosquitto.exe -v -q. I observed following response
mosquitto is an MQTT v3.1 broker. Does it support MQTT5.0? If not how to install server which supports MQTT5.0. I have to test my application with MQTT5.0 server.
Thanks,
Vinod
Mosquitto v 1.5 and above support mqttv5. When you start it what version is it showing.
rgds
steve
I have installed mqtt following steps, now i want to connect to it using MQTT Client application how is that possible /.?
Hi
Take a look here
http://www.steves-internet-guide.com/mqtt-python-beginners-course/
and
here
http://www.steves-internet-guide.com/mosquitto_pub-sub-clients/
Hi Steve,
I installed Mosquitto as a service in the V1.6.2 version of windows server2012.
Max_connections=500 is set, memory_limit=524288000.
1. Start the proxy service
2. Create a new connection with a loop. When the number of connections reaches the maximum number of connections, the proxy service refuses to connect and closes the test program.
3. Re-run the test program, then the number of connections created will exceed the maximum number of connections set to 500. After repeating this operation, the proxy service will crash.
But what I don’t quite understand is that the maximum number of connections has been set, but when I run the test program for the second time, the number of connections has exceeded the maximum number of connections set?
Excuse me? What parameters do I need to configure? Can you avoid this problem?
Are you testing mqtt or mqtt over websockets? What proxy?
Rgds
Steve
I am sorry,”proxy service” is the Mosquitto service
I am using mqtt
I haven’t tested the connection limit but I’ll give it a try and let you know.
Rgds
Steve
Hi Steve,
I installed mosquitto in Windows 10 as service and it works well with the default mosquitto.conf with anonymous authentication. I want to individualize access, so I changed mosquitto.conf as you say in “Mosquitto Username and Password Authentication” and than I restarted the mosquitto service. The service do not restart and I receive the message “O servico Mosquitto Broker em Computador local foi iniciado e interrompido. Alguns servicos sao interrompidos automaticamente se nao estiverem sendo usados por outros servicos ou programas”. In English is more or less: “The Mosquitto Broker service in Local Computer was started and interrupted. Some services are automatically interrupted if they are not used by other services or programs”. There is no way to restart the service, neither rebooting. If I return the mosquitto.conf to the default (without authentication) the service restarts and mosquitto works well. I do not understand what is the problem, can you help me? Thank you – Filippo Pardini
Hi
You have very probably made an error when editing the conf file.
When doing testing a prefer to start mosquitto manually rather than as a service as it is quicker to test.
The error reporting whem starting mosquitto is not very clear.
The sc start mosquito command needs to be an Admin Command Prompt not a “normal” Command Prompt otherwise thank you.
FYI to install version 1.5.4 as a windows service was as simple as launching powershell as an administrator and running the following:
c:\program files\mosquitto\ ./mosquitto install
Ian
Thank you very much for that I will add it to the tutorial
rgds
steve
hi steve,
i successfully installed mosquitto on my machine and verified it by checking port 1883 and it was “listening”. but still when i try to run basic commands to subscribe or publish it doesnt work.
Start mosquitto with the -v option then you can see if the clients are trying to connect.
Steve,
I have a small Single board computer running Windows 10 Enterprise (Latte Panda module).
I have been through your tutorial several times and cannot get the installer running.
If I copy your files into a folder called “Moz” and then in command line run Mosquitto -V then the server does start up ok.
When I go to the Mosquitto site and download latest version of Mosquitto (32 bit), and install in the same MOZ folder, it cannot find the files in that folder and does not run. Does the version of Mosquitto matter? the downloads are different than your descriptions. Thsnk
If the newer version doesn’t run after install then I would suspect a path issue.
Have you tried going to the folder were the installer installs the files and running from there?
The only thing the installer does beside copying over the files is to configure mosquitto to start as a service which you can also do manually.
I haven’t checked what files are included with the latest version but It is on my todo list but the ones in my zip package should cover everything except web sockets.
Are you going to use web sockets?
Even easier , just install Windows Linux subsystem, here’s nice write up of how to do it.
http://www.abrandao.com/2018/03/running-mosquitto-mqtt-on-windows-10-super-easy/
when i type C:\>mosquitto>mosquito in the command prompt …it says access is denied can anyone pls help
might just be a typo
Hi,
Try to run mosquitto broker and cliënt on raspberry pi3.
Get always connection refuzen not authorised.
Someting with the User? The netstat -t give a time_wait?
Thks for your help,
Frederik
This guide was really usefull!
First time playng with MTTQ, I of course chose to follow the “hard way” to install mosquitto on Windows 10 (- LOL -)…
After some hours… I realized that the last Win32OpenSSL_Light version (v 1.1.0) doesn’t contein the two requested files (libeay32.dll ssleay32.dll), and I sorted out using the version 1.0.2n…
Then I had the VCRUNTIME140.dll issue, and this was fixed installing ‘Microsoft Visual C++ 2015 Redistributable (x86)’ (32bit version), as discribed in others comments.
And at last… I can turn on and off a led on my ESP-01 sending MTTC command (oops… “publishing”…) from my PC using mosquitto_pub…
Great!!!
Hi Steve,
Thank for taking the time and creating this Zip file.
I was stuck with my mosquitto install (win 10 Pro / x64) and actually was at a point to consider running mosquitto in VM 🙂
Glad it helped
Steve
Congrats man !!!!!
Thank you so much !
Hi Steve,
I had almost given up installing mosquitto on windows until I found your tutorial. Success! The zip file was extremely helpful.
Thanks,
Carter
I know how you felt it took me a while to get it working when I first installed it.
Glad it helped
Hi Steve
in the installation process at the end I get an error called The program can’t start because VCRUNTIME140.dll is missing from your computer. Try reinstall the program to fix this problem
Hi
Did you try downloading the zip package that I put together. Unzip it and copy it to a directory and then run the broker from the command line from there. There is no need to install it.
http://www.steves-internet-guide.com/downloads/
Hi All,
I had the VCRUNTIME140.dll issue when I install MQTT just now, and I search the issue at web, have a solution it’s Visual C++ Redistributable for Visual Studio 2015 installed, I just download the file and installed, and re-install mosquitto, the problem has been solved, hope the information can help you.
Note that you need to install 32-bit version of it. I had 64-bit version (x64) but it is not compatible with this and the symptom was that I could not start mosquitto and the error message was ‘The application was unable to start correctly (0xc000007b)’
After installing ‘Microsoft Visual C++ 2015 Redistributable (x86)’ it started.
You can download from here:
https://www.microsoft.com/en-us/download/details.aspx?id=52685
Yes, i was facing the same problem.
with your reply issue is resolved.
Thank You Very Very Much
Hi Steve,
How to add a listener with a new port in Ubuntu mosquitto-broker?
add the line
listener 1884
to add a new listener on port 1884
Rgds
steve
Hi steves
I followed you and it works correctly.
Butwhen I stopped mosquitto as below, publish and subscribe work again!!!why?
code :
pc@ubuntu:~$ sudo /etc/init.d/mosquitto stop
[ ok ] Stopping mosquitto (via systemctl): mosquitto.service.
pc@ubuntu:~$ mosquitto_pub -d -t /topic1 -m myMessage
Client mosqpub/7237-ubuntu sending CONNECT
Client mosqpub/7237-ubuntu received CONNACK
Client mosqpub/7237-ubuntu sending PUBLISH (d0, q0, r0, m1, ‘/topic1’, … (2 bytes))
Client mosqpub/7237-ubuntu sending DISCONNECT
mosquitto_sub -d -t /topic1
Client mosqsub/7104-ubuntu sending CONNECT
Client mosqsub/7104-ubuntu received CONNACK
Client mosqsub/7104-ubuntu sending SUBSCRIBE (Mid: 1, Topic: /topic1, QoS: 0)
Client mosqsub/7104-ubuntu received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/7104-ubuntu received PUBLISH (d0, q0, r0, m0, ‘/topic1’, … (2 bytes))
myMessage
why???
It doesn’t look like it is being stopped or it may be automatically restarting. Ubuntu installs don’t use the init scripts.
Try using the sudo service mosquitto stop command.
You can check using netstat -at command
Thx!
I tried to install my web server(windows server 2016(64bit) and
lots of error makes me crazy.
I spent time almost 12h to catch errors.
But this articls’s quick install method is only work on my server.
Excellent. Your zip file was EXTREMELY helpful 🙂
Ian
Ian
Glad it helped
Steve
hi,
my subscriber is written in golang.
and i try to install it in windows..
now i need to install some of the mqtt package which is used in the golang program
MQTT “git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git”
_ “github.com/lib/pq”
how do i do that ?? many thanks
Sorry I don’t have any experience with golang
Thank you very much! Your post is very useful!