Raspberry Pi Adventures

Join me on my fun ride

Mosquitto MQTT on Raspberry Pi [Broker – Publish and Subscribe Client]


Using OS : 2012-08-16-wheezy-raspbian

Grab the latest build from

I downloaded the following


1. Created a “Mosquitto_MQTT” directory
$ sudo mkdir Mosquitto_MQTT

2. Copied the “mosquitto-1.0.2.tar.gz” to the the following path using WinSCP

Refer my WinSCP and Putty Tutorial for help with Copying file and Putty Usage.
Enabling SSH on Raspberry Pi and using Putty and WinSCP « Raspberry Pi Adventures


Follow these commands to Install
$ sudo apt-get install libwrap0-dev
$ tar zxf mosquitto-1.0.2.tar.gz
$ cd mosquitto-0.15
$ make
$ sudo make install
$ sudo ldconfig
$ sudo make clean
$ sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT


Configuration File Location for Reference



Putty Window 1 – Raspberry Pi

Start Mosquitto Daemon on Raspberry Pi using Putty
$ mosquitto


Putty Window 2 – Raspberry Pi – Subscribe
Open Putty Connection 1 to Raspberry Pi To Subscribe

$ mosquitto_sub -d -t hello/world

$ mosquitto_sub -h raspberrypi -d -t hello/world

$ mosquitto_sub -h -d -t hello/world

Where is your Raspberry Pi’s IP Address


Putty Window 3 – Raspberry Pi – Publish
Open Putty Connection 2 to Raspberry Pi To Publish

$ mosquitto_pub -d -t hello/world -m "Message To Send"

$ mosquitto_pub -h raspberrypi -d -t hello/world -m "Message To Send"

$ mosquitto_pub -h -d -t hello/world -m "Message To Send"

Where is your Raspberry Pi’s IP Address

Note: Messages you type in Publish Window will be visible in Subscribe Window


MQ Telemetry Transport » wiki » mosquitto_message_broker
Hello MQTT — Michael Connors
Getting Started with MQTT

Author: Sanket Sonavane

Sanket Sonavane Senior Developer, IoT Enthusiast, Photographer, Bike Rider, Chef, AndroidUser, MacOSX Fanatic ;) Loves computers, programming, web developement, micro-controllers, gadgets, automation and many more such tech innovations that defines the way we live in the modern age and likes to explore what more can be done to help the human race :)

5 thoughts on “Mosquitto MQTT on Raspberry Pi [Broker – Publish and Subscribe Client]

  1. In this project what can I do if I have different IP address in my mobile and I aslo want to connect with that same address…so please help me regard this.

    • I have installed putty in my laptop and I am using Raspberry Pi 3..I can successfully publish and subscribe the message with mosquitto command ..but I am doing this all in for perticular 1 ip address by which all the devices are connected but what if i want to send message means publish or subscribe the data with another ip address. So please help me as soon as possible.


  3. Hi Amey, Thanks for the inputs. Its been almost 3 years since i wrote that article , i have procured a new raspberry pi 2 will experiment the same and try to make additions to this article.

  4. Thanks Sanket for the nice post. It was really helpful!
    In addition to your post , I would like to add few comments for the same:
    Before executing the make command following package may be required:
    1) sudo apt-get install libssl-dev
    2) In config.mk change WITH_SRV:=no
    3) sudo apt-get install uuid-dev

    I got issues while running mosquitto-1.4.3.tar.gz on raspberry pi B model and these issues were solved after installing above packages.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s