Categories
Linux Ubuntu

MQTT

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

connection

Subscribe & Publish

publish_subscribe

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.

 

By Abhishek Kumar

My name is Abhishek Kumar. I am a Software Engineer from India. I stay in Pune a city in south western India. Pune is a city known for IT services companies.

The main purpose of the writing this blog is to keep collection of my projects done by me.

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 )

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