How to Install The Mosquitto MQTT Broker- Windows and Linux #broker #check


#

How to Install The Mosquitto MQTT Broker- Windows and Linux

It is available as a free download, and In this tutorial we are going to cover installing the mosquitto MQTT broker on Windows and Linux, and then testing the installation.

Installing The Mosquitto Broker on Windows

There are good detailed install instructions for windows here.

It is important that you install the addition files. and copy them to the mosquitto directory as mentioned in the article.

To get these additional files you will have to install additional software packages and copy them from there.

However if you have these files already then you can use them on other machines without going through the install see quick windows install below.

This is what the mosquitto directory looks like when finished.

Note 1: above screenshot is missing some files from cygwin as it was installed and the files were in the right path.

Note 2: there is readme-windows.txt file in the mosquitto install directory that you should read

Here is a complete list of additional files that you need:

cygcrypto-1.0.0.dll
cyggcc_s-1.dll
cygssl-1.0.0.dll
cygwin1.dll
cygz.dll
libeay32.dll
libssl32.dll
msvcr100.dll
pthreadVC2.dll
ssleay32.dll

Quick Windows Install

If you have already installed Mosquiito on another windows machine e.g. XP and want to install it on another machine e.g. Windows 10 just copy the directory containing the mosquitto files.

I copied my windows XP install (32 bit) onto a window10 (64bit) machine and it worked OK.

I ve create a zipped directory which I ve used on Windows 10 and Windows 7.

You can download it here Don t forget to virus check it let me know if you have any problems with it.

Just unzip it go to the directory and run the broker manually as covered below.

Starting Mosquitto on Windows

If the mosquitto broker starts as a service then you will need to stop it.

To stop a service go to control panel admin tools services .

You can stop the broker and change the automatic startup settings so it doesn t automatically start on Windows start up.

Note: On my install (on XP) it wouldn t start as a service and gave error code 1053. This wasn t a problem because I wanted to start it manually anyway.

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

Installing The Mosquitto Broker on Linux

The download links and install directions for LInux are here

I followed the install instructions for Ubuntu but they seemed to miss a few important steps. Here are the steps I used for Linux Mint.

  • sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
  • sudo apt-get update
  • sudo apt-get install mosquitto
  • sudo apt-get install mosquitto-clients

It should automatically start mosquitto.

To Stop and start the service I needed to use

Most sites I discovered where using the format.

However it seems newer installations use upstart initialization system instead of the init.d initialization system.

The stop/start scripts start the mosquitto broker in the background and also use the default mosquitto.conf file in the /etc/mosquitto/ folder.

If you want to see control messages on the console then you need to start the mosquitto broker from a command line.

You first need to to stop the broker from running, and then type:

Testing The Install

To test it is running use command:

You should see the Mosquitto broker running on port 1883 as shown in the screen shot above.

Starting Mosquitto Using a Configuration 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 mosquitto using a configuration file use the following command:

On windows the mosquitto.conf template file is found in the mosquitto directory.

On linux you can find the mosquitto.conf template file in the /etc/mosquitto/ folder.

It is a good idea to create a copy of this file before editing it.

Enabling Logging

This is useful for troubleshooting. Logging is already enabled in the default config file so all you need do is start mosquitto with this config file.

Important Note: on Linux although you stop mosquito from running using the command

to start it use:

On Windows you may also need to specify the path to the config file e.g.

You can also use a command line switch -v to enable logging:

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

Start mosquitto and listen on port 1883

mosquitto -p 1883

Start mosquitto as a daemon and listen on port 1884

mosquitto -p 1884 -d

Start mosquitto as a daemon and use the mosquitti-2.conf file. – Windows

mosquitto -c c:\mosquitto\mosquitto-2.conf -d

mosquitto -c /etc/mosquitto/mosquitto-2.conf -d

Useful Linux Commands

To stop Mosquitto when running as a daemon:

ps -aux | grep mosquitto
pgrep mosquitto
kill -9 PID (that you get from above command)

Mosquitto Client Scripts

The windows install includes the client scripts, on Linux they need to be installed. Use

There is a simple subscriber client

and a publisher client

  • I didn t get the scripts to work on Windows XP -Error not a vaild win32 application
  • On Windows 7 and 10 they gave an error regarding a missing msvcr100.dll file. I found the file on my system and copied it to the Mosquitto directory and they worked OK.

Other Tools

It lets you publish and subscribe to topics using a web interface, and is much easier to use than the command line clients.

My Python MQTT Scripts -Collection of python scripts that you may find useful.

Mosquitto Configuration Tutorials

Other Related Articles and Resources:

Was This Article Helpful? Please Rate..

$ sudo /etc/init.d/mosquitto stop
[ ok ] Stopping mosquitto (via systemctl): mosquitto.service.

$ 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

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



Leave a Comment

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