Installing MQTT Broker on Windows

If you don’t have any idea about what is MQTT protocol. please click on the following link to know what is MQTT protocol.
What is MQTT Protocol

Install MQTT Broker on Windows Computer

Please follow the following steps to install the MQTT Broker on Windows Computer
1)Download the MQTT Broker. To download click on the following link.
Download MQTT Broker
2)Under Windows, Choose .exe file according to your computer. For 32 bit computer click on the x32.exe file and for 64-bit computer click on the x64.exe file.

3)After Downloading , double Click on the Downloaded .exe file.
If it is showing message Windows Defender SmartScreen prevented , then Click on More info and then Click on Run anyway. It shows Windows Defender SmartScreen prevented, when Windows Defender of your PC is enabled .
4)Click on NEXT

5)Click on NEXT

6)Click on NEXT

7)If you want to change installation path , Click on Browse and choose the path and Click on Install

8)Click on Finish





9)Optional step. please follow this only when you want to install MQTT broker on another port. If you want to change MQTT listening port then open  mosquitto.conf (right click on file and click on open with) with Notepad++ or any another editor and modify port portnumber which is shown below.

10)Open Command Prompt as Administrator. Steps are given below.
Search command Prompt in your computer -> Right click on command prompt -> Run as Administrator

11)Navigate to Folder/Path, where your broker is installed. Please see Step 7 to know, your Broker installed path. for navigation use following command
cd C:\Program Files (x86)\mosquitto
12)Execute the following commands to Install Broker and start Mosquitto Service.

mosquitto install
net start mosquitto


After executing command net start mosquitto, If you are getting the message
The Mosquitto Broker service was started successfully means Mosquitto Broker Installed Successfully.

13)Now please open the port 1883.  To open port 1883 on windows, please click on the following link.
How to open port in Windows




MQTT CLIENT

Below various mqtt clients are given by using those mqtt clients you can publish or subscribe data. mqtt clients given below such as mqtt client using ESP8266 or NODEMCU, mqtt client using python, mqtt client using java etc.

ESP8266 AS MQTT PUBLISHER AND SUBSCRIBER

PYTHON AS MQTT PUBLISHER AND SUBSCRIBER

JAVA AS MQTT PUBLISHER AND SUBSCRIBER

WINDOWS COMMAND PROMPT AS MQTT PUBLISHER AND SUBSCRIBER

UNINSTALL MOSQUITTO ON WINDOWS:

If you want to uninstall mosquitto or mqtt broker , please follow the following Steps to uninstall mosquitto or mqtt broker.
1)Open Command Prompt as Administrator.
2)Navigate to mosquitto installed folder . please see step 10 above.
3)Execute the following command to stop mosquitto Service on windows.

net stop mosquitto

4)Execute the following command to uninstall mosquitto.

mosquitto uninstall


5)Now close the command prompt and delete mosquitto folder.



Common Doubts:

1)Can I change MQTT listening port?

Yes, you can change MQTT listening port. If you are trying to change MQTT port at the time of intstallation then please follow the step number 10.

2)Can I change MQTT listening port after installing MQTT broker ?

yes, you can change. To change please follow the following steps.

A)Please follow the step number 9 and save the changes.

B)Open command prompt in Adminstrator mode. follow the step 10 to open command prompt in adminstrator mode.

C)Stop the MQTT service. Use following command to stop MQTT service.

net stop mosquitto

D)Now Start MQTT service. Use following command to stop MQTT service.

net start mosquitto

3)Can I implement WebSocket over MQTT?

yes , you can implement WebSocket over MQTT. Please click on the below link for implementing websocket on MQTT.

MQTT WebSocket

Common Mistakes/Problems:

1)You will forget to open the command prompt in Administrator mode.

2)If your windows defender is enabled then you have open MQTT port 1883 manually.
How to open port 1883 in Windows

3)MQTT broker will not work if any service is running on port 1883. So please ensure that none of the services is running on port 1883. If any service is running on port 1883 then either stop that service or install MQTT broker on another port. Please see step 9 to modify the MQTT port.

4)If you have modified MQTT port then you should always send and receive data on modified port number, not on the default port.

5)A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond?

You will get an error, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond because of the one of the following six reasons.

1)When Host does not exist?

The host does not exist means you have entered the wrong host name or wrong host IP address or MQTT broker is not running on the entered Host.

2)Open port on windows ?

You will also get above error when MQTT port  is disabled. So please open port 1883 on windows which is default MQTT port. To open port 1883 on windows, please click on the following link.
How to open port in Windows

3)Firewall is blocking incoming connections

Whenever firewall blocks incoming connections then also you get the above error message. In this case, you need to unblock all incoming connections. Please click on the following link to unblock or allowing firewall incoming connections.
Firewall allowing incoming connection

4)When windows Defender is enabled?

When windows defender is enabled on your system and you are trying to install any service on your system then ports related with that service do not open automatically, then you need to open the ports related to that service manually. If MQTT port 1883 is not open then also you get above error message so please click on the above given link to open port 1883 on windows.

5)Allow app through windows defender firewall

If windows defender firewall is not allowing mosquitto app then also you will get the above error, so please follow the following steps to allow mosquitto through windows defender firewall.

1)Please press Windows + R of your system to open firewall.

2)Now please type firewall.cpl and click OK which shown below

3)Now please click on Allow an app or feature through windows defender firewall which is shown below.

4)Now search for mosquitto and tick all the boxes of mosquitto and click ok which is shown below.

6)Turn off windows defender

If your are getting above error please turn off windows defender. If you do not know how to turn off windows defender please click on below link,
how to turn off windows defender

7)restart mosquitto or MQTT broker

If above 6 ways are not working then restart mosquitto or MQTT broker. Please follow the following steps to know, how to restart mosquitto or MQTT broker:
a)Open the command prompt as administrator. follow the step 10 to open command prompt in adminstrator mode.
b)Execute the following command to stop mosquitto service

net stop mosquitto

c)Execute following the command to start mosquitto service

net start mosquitto

Video link- How to install MQTT broker on windows

You may also like...

4 Responses

  1. John Darer says:

    This іs a topіc that’s clοse to my heart… Many thanks!
    Exactly where are you cоntact details though?

  2. after doing this in my xamp

    i am getting this error

    PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\\xampp\\php\\ext\\mosquitto.dll’ – The specified module could not be found.\r\n in Unknown on line 0

    Please help me what i need to do in this case?

    • admin admin says:

      Are you using port 1883 on your system before installing MQTT broker on your system?
      if yes then you have to install mqtt broker on another port.
      Please see step 10 for modifying mqtt Port

Leave a Reply