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 http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
  4. sudo apt-key add mosquitto-repo.gpg.key
  5. cd /etc/apt/sources.list.d/
  6. **skip n try***sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
  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 Subscriber.py)

MQTT_BROKER = "your IP address"
MQTT_PORT = 1883
MQTT_KEEPALIVE_INTERVAL = 45
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_KEEPALIVE_INTERVAL = 45
MQTT_TOPIC = "testTopic"
MQTT_MSG = "Hello MQTT"

Find detailed guidelines clicking here.

Please find full documentation : https://mosquitto.org/

 

Have fun and develop the future !

Mauricio Silva

Leave a Reply