Mosquitto MQTT Broker

install mosquitto iconMosquitto is a lightweight open source message broker that Implements MQTT versions 3.1 and 3.1.1.

It is written in C by Roger Light, and is available as a free download for Windows and Linux and is an Eclipse project.

The main website is here.

Installing The Broker

To use it you will first need to install it.

Starting and Stopping The Broker

Depending on the install it will probably be started automatically on system startup.

On Windows you can stop the service if it is running by using the control panel>admin>services.

You can also the net command:

net stop mosquitto

On Linux use:

sudo service mosquitto stop

Starting from command line is the best option when testing and to do that use:

Windows and LInux

mosquitto -v   #start in verbose mode

To see other start options use:

mosquitto -h

By default the broker will start listening on port 1883. You can change that by editing the configuration file-mosquitto.conf See Quick Guide to The Mosquitto.conf File With Examples

Alternatively you can use a command line switch to specify the port e.g.

mosquitto -p 1884

You can run Multiple brokers on the same machine by starting them on different ports See this video- on running multiple brokers.

Mosquitto Client Scripts

The mosquitto install includes the client scripts.

There is a simple subscriber client

mosquitto_sub

and a publisher client

mosquitto_pub

 

They are useful for some quick tests. See Using The Mosquitto_pub and Mosquitto_sub Client Tools- Examples



Other Tutorials

Facebooktwittergoogle_plusredditpinterestlinkedinmail

7 comments

  1. Hi Steve,
    We have subscribed to a basic package of freeboard and we are facing difficulties in linking our test mosquitto MQTT server to freeboard.
    We have successfully completed the data transfet between the TEST MOSQUITTO SERVER and OUR PLC.
    The below are the configuration settings in our PLC ( Programmable Logic Controller )

    1. TYPE : MQTT
    2. NAME : ( Any name )
    3. TOPIC : qwerty ( Advice )
    4. SERVER : 37.187.106.16 ( Advice )
    5. PORT : 1883
    6. USE ENCRYPTION : NO
    7. CLIENT ID : mqttdemo ( Advice )
    8. API KEY / USERNAME : steve
    9. PASSWORD : john
    10. JSON MASSAGES : no

    With these settings we tried these out, But the connection could not be accomplished. Please advice.

    Regards,

    Satheesh Kumaran

    1. Can you point me to the instructions you are following.You might also want to use the ask steve page as I don’t have a freeboard account and you might need to let me access using yours.
      rgds
      steve

  2. Hi Steve.
    Thanks for your publications. I recently had a question for you and your answer was very helpful. I have another one. I installed Mosquitto broker in Raspberry Pi. After a lot of problems I finally managed to have it running. I have one application (IoTView by an industrial software manufacturer) who is accessing the broker, suscribing and publishing. At the same time I have another application (Web Studio) from the same manufacturer running on a PC, acting as a server who records the information on a database. On the tests, only one of them (IoTView) could run with no problems, while the other one stop working. I have been doing modifications for several months thinking the problem was on the application. Yesterday the manufacturer let me know the problem was on the Broker running on Raspberry Pi. It could not attend two connections at the same time…. Since you know this subject more than anyone I know, I would like your opinion. Is that so? It makes no sense for me that the broker on Raspberry Pi can attend only one connection at the same time. Is there not a parameter whom I can modify to alter this? The manufacturer reccomendation was to switch and install a broker on the Server. The PC running windows.

    1. Hi
      I run Mosquitto on Pi with multiple connections. Are you using different client names for the clients? The client ID needs to be unique.
      Also start the broker with the -v option so you can see the connections and responses.
      rgds
      steve

Leave a Reply

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