How to Install The Mosquitto MQTT Broker on Windows

install mosquitto icon 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

This version works with websockets.

Here is my download package 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.

mosquitto-install-windows-binaries

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 clearmosquitto-install-windows-dependencies

3. Select components check service to install as a service.

old-windows-mosquitto-install

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.

mosquitto-windows-start-manual

You can also use various command line switches. Type

mosquitto -h

for help.

mosquitto-help

To start in verbose mode so that you can see console messages use the -v option:

mosquitto-start-verbose-windows

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

mosquitto-windows-service

Note you need to open the command prompt as administrator.

dos-prompt-admin

Installing Mosquitto as a Service using Power Shell

Open a power shell command prompt as administrator.

runPowershell

Change to the directory where you have installed mosquitto (mos154 below) and type:

./mosquitto install

install-mosquitt-service-windows10

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

start-mosquitto

Testing The Install

To test it is running use command:

  • netstat -a

netstat-windows

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.mosquitto-error-port

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. .

Don’t use the commented out version and edit it as it is very long and difficult to navigate.

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

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

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

MQTTlensMQTTlens 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-icon 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

Other Related Articles and Resources:

Please rate? And use Comments to let me know more
[Total: 24    Average: 4/5]

40 comments

  1. 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?

  2. 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

    1. 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.

  3. The sc start mosquito command needs to be an Admin Command Prompt not a “normal” Command Prompt otherwise thank you.

  4. 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

  5. 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.

  6. 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

    1. 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?

  7. when i type C:\>mosquitto>mosquito in the command prompt …it says access is denied can anyone pls help

  8. 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

  9. 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!!!

  10. 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 🙂

  11. 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

  12. 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

    1. 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.

      1. 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.

  13. 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???

    1. 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

    2. 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.

  14. 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

Leave a Reply

Your email address will not be published. Required fields are marked *