Using OS : 2012-08-16-wheezy-raspbian
Grab the latest build from
http://mosquitto.org/download/
I downloaded the following
http://mosquitto.org/files/source/mosquitto-1.0.2.tar.gz
Steps
1. Created a “Mosquitto_MQTT” directory
$ sudo mkdir Mosquitto_MQTT
/home/pi/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
/etc/mosquitto/mosquitto.conf
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
OR
$ mosquitto_sub -h raspberrypi -d -t hello/world
OR
$ mosquitto_sub -h 192.168.1.2 -d -t hello/world
Where 192.168.1.2 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"
OR
$ mosquitto_pub -h raspberrypi -d -t hello/world -m "Message To Send"
OR
$ mosquitto_pub -h 192.168.1.2 -d -t hello/world -m "Message To Send"
Where 192.168.1.2 is your Raspberry Pi’s IP Address
Note: Messages you type in Publish Window will be visible in Subscribe Window
References
MQ Telemetry Transport » wiki » mosquitto_message_broker
Hello MQTT — Michael Connors
Getting Started with MQTT
April 10, 2017 at 5:33 PM
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.
April 10, 2017 at 5:46 PM
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.
Pingback: MQTT – EMBEDDED SYSTEM
September 16, 2015 at 10:08 AM
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.
September 14, 2015 at 11:18 AM
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.
Regards
Amey