Nothing Special   »   [go: up one dir, main page]

How To Install and Use Mosquitto For Windows

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

How to install and use Mosquitto for

Windows

Introduction
Mosquitto is an application for the MQTT protocol. It can be used as a broker, subscriber
and publisher.
This guide will covers how to use Mosquitto as an application, not as a Windows service.

Installation
Download Mosquitto from ​https://mosquitto.org/download/​ and install it.

If you install it with the “Service” checkbox checked, it will start automatically with Windows
and ​occupy the default port 1883.
If you installed Mosquitto this way you can disable the service by going into the ​Services
menu in Windows and pressing the stop button with the ​Mosquitto Broker​ selected.

The default installation path will be: ​C:\Program Files\mosquitto


The directory should look like this if the program installed correctly.
Usage
The installation path is by default: ​C:\Program Files\mosquitto
Navigate to the folder with cmd.exe using ​cd C:\”Program Files”\mosquitto

Running the broker


Running the command ​mosquitto.exe -v​ will start the broker and put it in ​verbose ​mode,
enabling debug messages etc.
The broker is now running, any connecting subscribers or published messages will show up
as prints in this window.

When a subscriber subscribes to your broker, it will look something like this.

Running the subscriber


Running the command ​mosquitto_sub.exe -t ​*your topic here*​ will start the subscriber and
subscribe to the topic specified instead of ​*your topic here*.​
If not specified, the default IP is your local IP.
If not specified, the default port is 1883

This subscriber is now subscribed to the topic ​testTopic​ on the broker running on the local
IP on port 1883.

To subscribe to another IP and/or another port use ​-h ​*IP here*​ ​-p *port here*​ as additional
arguments when starting mosquitto_sub.exe

This broker is now subscribed to the topic ​testTopic​ o


​ n ip ​140.2.66.130​ on port ​1234.

Using the additional argument ​-d​ will enable debug prints.


Running the publisher
Running the command ​mosquitto_pub.exe -t ​*your topic here* ​-m ​*”your message
here”*​ will start the publisher and send a message to the topic specified with the message
specified.
If not specified, the default IP is your local IP.
If not specified, the default port is 1883

This publisher has just sent a message to the broker on my local computer, on port 1883, on
topic ​testTopic​ with the message ​Test message.​

To publish to another IP and/or another port use ​-h ​*IP here*​ ​-p *port here*​ as additional
arguments when starting mosquitto_pub.exe

Using the additional argument ​-d​ will enable debug prints.

This publisher just sent the same as above, although this time with debug messages
enabled.
Broker, sub and pub all working together

A printscreen of all 3 different programs running one one computer. The broker in the top
right, subscriber in top left and publisher in bottom left.

Troubleshooting

If you get an error telling you that “normally only one user is allowed per socketaddress
(procol/network address/port)” you might have another application already running, listening
on port 1883. Check if you already have another cmd window with a broker running on the
same port. Alternatively a Mosquitto broker might be running already as a service. Scroll up
to the ​installation section​ of this guide to see how to fix this.

You might also like