MQTT is simple publish subscribe message broker, which is used for IOT based machine to machine (M2M) communication. It is simple to use. It needs a MQTT server, which can be hosted on any linux or windows machine.
Execute The following line with root privilege, it would import security code and add to local key repository and install mosqitto service.
$wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key $sudo apt-key add mosquitto-repo.gpg.key $cd /etc/apt/sources.list.d/ $sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list $sudo apt-get install mosquitto
Making mosquitto secure – Add below lines to the file /etc/mosquitto/mosquitto.conf. This would make the mosquitto listen on port(8883) at all the interfaces connected to Raspberry pi.
listener 8883 0.0.0.0 password_file /etc/mosquitto/pwfile
Update the password file with the username you want to connect to the mosquitto service and restart the mosquitto service.
$ sudo mosquitto_passwd -c /etc/mosquitto/pwfile mqtt Password: Reenter password: $ sudo service mosquitto restart $ ps -aef | grep mosq mosquit+ 2150 1 0 09:55 ? 00:00:00 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Testing the service – You can use many clients, e.g. python paho-mqtt, android based client, online client. I have used chrome based app called MQTTLens. It can be found on chrome app store.
Add a New connection
Subscribe & Publish
To remove mosquitto run apt-get purge.
$sudo apt-get purge mosquitto
There can be multiple use of MQTT, I will use this to communicate with raspberry-pi, ESP8266 and Arduino modules in coming posts.