Install Mosquitto MQTT Windows

Posted on

by

in

Install Mosquitto MQTT Windows

Introduction

This post will discuss how you can install Mosquitto MQTT broker on a Windows machine. MQTT or MQ Telemetry Transport is a publish-subscribe lightweight protocol. This protocol is ideal for memory or bandwidth-constrained devices like our microcontroller.

We will begin the installation process by installing the Mosquitto MQTT broker on a Windows machine and then do the necessary configuration. After that, we will do the initial testing of a publish-subscribe cycle to verify the installation.

Prerequisites

You will need a workstation or laptop running Windows and with sufficient CPU power and memory. Also, ensure you have sufficient Administrator privileges so we don’t encounter any permission issues.

Steps

  1. Download the MQTT Broker from this link. When writing this post, the latest version is shown in the image below. Select if you want the 32-bit or 64-bit version.
MQTT Windows - download
  1. When the download is finished click the executable file. If a popup for user account control is shown then just click Yes. When this screen is shown click Next.
Install MQTT Windows - First Screen
  1. Click Next again on which components to install
Install MQTT Windows - Choose Components
  1. Please select where you want to install it but in my case, I have set it to the default installation folder and clicked the install button.
Install MQTT Windows - Choose Install Location
  1. Once the installation is finished then open a command prompt. Right-click and click the “Run as Administrator Option”
Command Prompt - Run as Administrator
  1. Change into the directory where you installed your Mosquitto broker and execute the below command to start the Mosquitto service.
net start mosquitto
net start mosquitto service

You should be able to see the following message above to be displayed.

If you go into the services then you will notice that the Mosquitto broker is now Running.

Mosquitto Broker Services

Testing our Mosquitto MQTT Broker

Now that we have successfully configured our Mosquitto MQTT Broker in our Windows environment then we will test it. To test it, we will send a publish and subscribe command on our same Windows machine. This would be enough to test if our installation is successful.

Subscriber client

  • Open a command prompt and change the directory into our Mosquitto installation then type in the below command.
mosquitto_sub -t test_sensor_data -h localhost

The command above subscribes to the topic test_sensor_data. Keep this command prompt window open. This is waiting for any publisher to publish any information on that topic.

mosquitto subscribe command prompt

Publisher client

  • Open a new command prompt and change the directory into our Mosquitto folder installation. Type in the below command and click enter.
mosquitto_pub -t test_sensor_data -h localhost -m “temp:100”
command prompt mqtt publish

This publishes a message about the temperature on the topic test_sensor_data.

If you take a look now at our subscriber command prompt window then you will see that the message is displayed.

mqtt test publish-subscribe command prompt

Congratulations! We now have a functioning Mosquitto MQTT broker on our Windows machine. Yay!

Adding the Mosquitto commands to the Windows PATH variable

Right now, when you want to execute the Mosquitto commands then you need to cd to the directory where you installed your Mosquitto software. If you want to access the mosquitto_pub and mosquitto_sub commands anywhere then you can add the Mosquitto folder to the PATH variable.

Follow the following steps to add your Mosquitto software to the PATH environment variable.

  • In your search bar, type in “environment”. Click the Edit the system environment variables
  • Click the Environment Variables
Windows Environment Variables
  • Search for the Path variable and click edit.
Edith Path environment variable WINDOWS
  • Add a New environment variable and paste it into the directory where you installed your Mosquitto server.
Add Mosquitto directory to Windows Path environment variable

Now, whenever you open a new command prompt then you can execute the mosquitto_pub and mosquitto_sub commands directly.

How to Uninstall Mosquitto MQTT Broker in Windows?

Open a command prompt and make sure that it is running in Administrator mode.

Type in the below command to stop the Mosquitto MQTT service first.

net stop mosquitto
mosquitto mqtt stop service

After which, type in the below command to uninstall the Mosquitto

mosquitto uninstall

Delete the installation folder if it was not deleted automatically.

Wrap Up

We have completed the process of how to install the Mosquitto MQTT broker on the Windows machine in this post. Also, we have run the configuration needed and then run the initial testing to verify our installation.

We are now ready to explore this awesome protocol in our IOT projects.

That’s it! Happy Exploring!

Read Next:
Pico W -MicroPython MQTT – BMP/BME 280 Weather Station
MQTT Tutorial using Arduino Framework

Read More:
Exploring Node-Red, Dashboard 2.0, and MQTT
How to build your own custom MQTT dashboard?

If you like my post then please consider sharing this. Thanks!

13 responses to “Install Mosquitto MQTT Windows”

  1. How to enable Websockets in Mosquitto? – donskytech.com

    […] Related Content: Install Mosquitto MQTT Windows […]

  2. Publish and Subscribe MQTT messages over WebSocket

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  3. MQTT using Node.js with practical examples – donskytech.com

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  4. How to test MQTT using MQTTX? – donskytech.com

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  5. MicroPython – MQTT Publish/Subscribe using ESP32/ESP8266

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  6. How to build your own custom MQTT dashboard?

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  7. MQTT Tutorial using Arduino Framework

    […] Content: Install Mosquitto MQTT WindowsHow to enable Websockets in Mosquitto MQTT […]

  8. Arduino MQTT Example Project – BMP/BME 280 Weather Station

    […] Content: Install Mosquitto MQTT WindowsMQTT Tutorial using Arduino […]

  9. Adafruit MQTT Library Tutorial – donskytech.com

    […] Content: Install Mosquitto MQTT WindowsPlatformIO Tutorial for Arduino […]

  10. Pico W -MicroPython MQTT – BMP/BME 280 Weather Station

    […] Content: Install Mosquitto MQTT WindowsPico W – MicroPython MQTT tutorial using umqtt.simple […]

  11. hark bachir Avatar
    hark bachir

    bien

  12. Node-Red – IoT Dashboard with Arduino – No Coding Required!

    […] Related Content: Install Mosquitto MQTT Windows […]

  13. Exploring Node-Red, Dashboard 2.0, and MQTT

    […] Posts: Install Mosquitto MQTT WindowsHow to test MQTT using […]

Leave a Reply

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