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

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 if you want mosquitto to start automatically when windows starts.

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

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.

mosquitto-service-windows

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

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.



Notes

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.

 

https://github.com/eclipse/mosquitto/issues/1934

Running In Docker

You can also run mosquitto on windows using docker see

running mosquitto in Docker

Mosquitto Configuration Tutorials

Other Related Articles and Resources:

Please rate? And use Comments to let me know more

76 comments

  1. Hello i am new at MQTT and i trying to set a communication with MQTT broker
    i Have a static IP at my PC 192.168.1.205 and when i insert it to MQTT broker i get the message disconnect
    when i put 127.0.0.1 i get the communication
    How can i change that?

  2. Hi, I used windows powershell to install the mosquitto as service. when I tried to start the service, it still comes out error 1053. Do u have any idea what has caused this?

    1. I would uninstall it and then install it again not using the power shell. They just introduced the power shell after I stopped training windoows and so never got into it.

  3. hello.
    i install mosquitto v2.0.11 in my device ,locally .but unfortunately i cant access this broken with another device.
    i add “listener 1883 ,allow_anonymous true ” first line in mosquitto.conf then stop and start again broken but i didn’t work .where am i wrong?
    i give this task when i write mosquitto -v:
    1615963221: Starting in local only mode. Connections will only be possible from clients running on this machine.
    1615963221: Create a configuration file which defines a listener to allow remote access

    1. It is probably because you are still using the old conf file you need to stop mosquitto as it is running as a service and then start it using the command
      mosquitto -c myconfigfile.conf
      where myconfigfile.conf contains those two lines
      When testing also start mosquitto manually. When finished place you conf file in the broker folder and rename it to mosquitto.conf and you can then let mosquitto start as a service again.
      rgds
      steve

  4. Hello Steve,
    I am using Mosquitto as a broker and the version is 2. I tried opening the broker on cmd in windows just for a test and tried mosquitto_sub -h “ip address” -t test but this always gives me error that |Error: No connection could be made because the target machine actively refused it.”
    I wonder how can I resolve it to just test if my broker is working or not?
    Thanks.

  5. hi Steve!
    I just watch your step to download the file you provide at the top, but when I press ” download ” , it just shows” invalid file type”, can you tell me what’s wrong with me?

    another question is that if I choose to download the file on the site, which should I download?
    there are 4 different files, and all the version is 1.1.1(what’s the difference from “Light”)
    thank you!

  6. Thank you very much! Your post is very useful!
    setx MOSQUITTO_DIR c:\mosquitto /m
    make my day longer 😀

  7. Hi Steve,

    I install Mosquitto as a service and configured the default config file to include the following lines.
    listener 1883
    allow_anonymous true
    However, connection is never a success until I point it the config file with the mosquitto -c command. Connection is terminated as soon as I close the cmd window.

    What do you think seems to be wrong? Thanks!

    Here are the results of the mosquitto -v command.
    c:\mosquitto>mosquitto -v
    1620493363: mosquitto version 2.0.10 starting
    1620493363: Using default config.
    1620493363: Starting in local only mode. Connections will only be possible from clients running on this machine.
    1620493363: Create a configuration file which defines a listener to allow remote access.
    1620493363: For more details see https://mosquitto.org/documentation/authentication-methods/
    1620493363: Opening ipv4 listen socket on port 1883.
    1620493363: Error: Only one usage of each socket address (protocol/network address/port) is normally permitted.

    1. You need to edit the /etc/mosquitto/mosquitto.conf file as this is used when mosquitto starts as a service.
      starting it from the command line you can create a conf file in the local folder. If you try to use the one in etc/mosquitto folder it probably wont work due to permissions.
      the last error message regarding port in use is because mosquitto us already started use
      sudo service mosquitto stop
      rgds
      Steve

  8. Hi Steve,

    I have installed mosquitto on azure VM (Windows server 2019), enabled in/out bounds for port 1883. Mosquito is running as a service but from different PC unable to connect using public IP. Connection never success in distributed environment

    I am using Mqtt Explorer

    listener 1883
    allow_anonymous true

  9. Hi Steve,
    I am using mosquitto installed on my machine with node mcu. What should I write in the code here?
    const char* mqtt_server = ??

    If it’s “test.mosquitto.org” , then won’t it be the online server? and I need it on my machine.

    TIA

      1. I put the ip address like this:
        const IPAddress server=(192,168,1,103);
        but it’s still not working. Is there something else i need to follow?

          1. In my code for nodemcu like this:
            const char * ssid=___;
            const char * password=___;
            const IPAddress server=(192, 168,1,103) ;
            I am using the built-in example in arduino. From pubsubclient>>mqtt esp8266
            When i used it with an online broker, it worked fine. I want it to run on my machine and i can’t figure out how to do that.

          2. I have mosquitto installed and running. I can even send and receive msgs via command prompt through msquitto. I just cannot get my nodemcu connected to it and I cannot figure out the problem. It would be a huge help if you can solve this issue.
            Regards,
            Noor

          3. Sorry I’m not familiar with nodemcu. Do you see a any activity on the broker when you try to connect. What script are you running on the device. Are you sure tcp/ip is working on the device

          4. It connected.
            Mosquitto was not allowing connections from anyone outside the machine, hence nodemcu was not connecting.
            -I added the following lines in conf. File:
            listener 1883
            allow_anonymous true
            -Save the file (while being in admin mode) and restart mosquitto service
            -In cmd prompt: netstat -a| findstr 1883 | findstr LISTEN
            -It will show 0.0.0.0:1883, and something like: [::]
            -It indicates anyone can connect to this machine’s broker now.
            -To add authentication, you can use client ids and passwords
            I hope this would be helpful to someone who is having this issue. Thankyou so much Steve for your help with this IP address thing.
            Regards,
            Noor

        1. Hey Noor. Im having the same problem. I couldnt connect my nodemcu to mqtt broker. I read what you’ve said but still i couldnt get it. Please help. Thankyou

          1. Hello, I’m from Brazil, your videos are helping me absurdly. But I have a problem for days that I can’t solve …
            When trying to connect to my local network using my ip (get in ipconfig command from cmd) I found problems, not connect, It is only connect using “localhost” ….
            I saw it in the comments to add the commands below to the file “mosquitto.config”:

            listener 1883
            allow_anonymous true

            I did that and restarted the mosquitto and the problem continues. I’m in doubt how do I add these commands …. Is it just editing the file and adding these lines at the end ??

            I need to make this work to continue my university project.
            The code below are show me when I type the command “netstat -a| findstr 1883 | findstr LISTEN” in cmd:

            C:\Users\felip>netstat -a| findstr 1883 | findstr LISTEN
            TCP 127.0.0.1:1883 LAPTOP-IJLVLL2N:0 LISTENING
            TCP [::1]:1883 LAPTOP-IJLVLL2N:0 LISTENING

          2. Glad the tutorials and videos help.
            When testing start mosquitto manually and use a config file in the local home folder so as to avoid permission issues.
            stop the existing mosquitto from running
            sudo service mosquitto stop

            create a basic conf file called test.conf with those two entries
            start mosquitto using
            mosquitto -c test.conf -v
            and try that
            rgds
            steve

          3. Dear Steve, I want to thank you for your help. I created the configuration file “test.conf” with the two entries:

            listener 1883
            allows_anonymous true

            When I wrote the command “mosquitto -c test.conf -v” and then created a “mosquitto_pub” and “mosquitto_sub” it just started working!

            However, it only works when I start the mosquitto manually with the command “mosquitto -c test.conf -v” ….

            Is there a way to start the mosquitto with the edited configuration file ??

          4. Yes just copy the file into the mosquitto folder using
            sudo cp test.conf /etc/mosquitto/mosquitto.conf

            rgds
            steve

          5. Hi Steve, I’m grateful for your help. My OS is windows… What the command for complete this task?

  10. Hey Steve,
    I am currently using Mosquitto and MqttLens. I cannot establish a connection to my IP with 1883 Port.
    Do you have any idea why that might be? Mosquitto Broker is running.

    Kind regards,
    Michel

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

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

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

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

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

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

          2. Check that no other instance of mosquitto is running using the same ports.
            rgds
            Steve

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

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

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

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

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

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

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

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

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

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

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

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

Leave a Reply

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