Create your own MQTT Broker for Raspberry Pi

Quick Reference for Install MQTT Broker in your Pi:

The following step are intended to install a MQTT Broker in the raspberry pi .I use A Raspberry Pi 2 model B with Wheezy .

Time to speak some “Bash” with the pi (Open the terminal):

  1. sudo mkdir mosquitto
  2. cd mosquitto
  3. sudo wget
  4. sudo apt-key add mosquitto-repo.gpg.key
  5. cd /etc/apt/sources.list.d/
  6. **skip n try***sudo wget
  7. sudo apt-get install mosquitto

Your MQTT service should be installed already:

Check your services status :

  1. service mosquitto status
  2. ps -ef | grep mosq
  3. netstat -tln | grep 1883


Test your service installing Paho Mqtt :

  1. pip install paho-mqtt

Then, run the  Subscriber  changing your IP address, in the MQTT_BROKER variable. (Remember to use : sudo python

MQTT_BROKER = "your IP address"
MQTT_PORT = 1883
MQTT_TOPIC = "testTopic"


Now, it is time for publish “HELLO MQTT” , using the topic “testTopic” in the broker we have created , again it vital to point your client application to the broker IP address. Run a new instance of the command and run the python Publisher using the sudo python command.


MQTT_BROKER = "MQTT Broker IP or DNS Name"
MQTT_PORT = 1883
MQTT_TOPIC = "testTopic"

Find detailed guidelines clicking here.

Please find full documentation :


Have fun and develop the future !

Mauricio Silva

Leave a Reply