Gunnebo Business Solutions, MQTT, Protocols, Raspberry PI, Technical

MQTT and ActiveMQ on RPI

MQTT  is an ISO standard publish-subscribe-based “lightweight” messaging transport protocol for use on top of the TCP/IP protocol. It is designed for connections with remote locations where a “small code footprint” is required or high latency/ low-bandwidth networks. Andy Stanford-Clark and Arlen Nipper of Cirrus Link authored the first version of the protocol in 1999.

This week we have installed played with MQTT and ActiveMQ on a Raspberry PI. Read more about it and try it yourself below!


To get rolling, we need a Raspberry PI3 and an SD card with Raspbian preinstalled. If you don’t have a preinstalled card, you can install Raspbian yourself by following this instruction.

Raspberry PI 3B from element14 that we will be playing with today

Next steps after installing Raspbian:
1. Open a terminal and run these commands to update to latest Raspbian and packages:

(This will take a short while)
2. Next open a terminal and run command:
sudo raspi-config
3. Now you will have to make some smaller configs to Raspbian
4. First open Advanced Options and choose Expand Filesystem
5. Secondly open Interfacing Option and Enable SSH and VNC
6. Exit the raspi-config and it will ask you to reboot

Steps to install working Java for ActiveMQ:
1. Open a terminal using CTRL+T and then run

ActiveMQ Installation

ActiveMQ is an open-source multi-protocol message broker with a core written around JMS. It supports MQTT and maps MQTT semantics over JMS.

Here are few steps to get it installed on RPI:

1. Create folder named in a place of your choosing, preferably in home folder

2. Download compressed file from Apache website, either manually or commandline:

3. Uncompress the downloaded file

4. To run ActiveMQ

(To run as service) or

(To run in terminal)

5. To enable start from boot:

b. And then this command to update rc.d

c. Now ActiveMQ should be started during boot

Node RED Installation

1. Run this command to update nodejs and Node-RED since it’s already installed in Raspbian

2. To run Node-RED, open a terminal and run

3. To enable Node-RED from boot:

4. Open browser and browse to localhost:1880 to configure flows and deploy them

Simple Flow

Here is a simple Node-RED flow illustrating subscribe/publish scenario.


Flow above is represented by the following json:

[{“id”:”8788d23c.6f5b2″,”type”:”mqtt in”,”z”:”b9bd2972.30ee88″,”name”:”Subscribe to /test/topic”,”topic”:”/test/topic”,”qos”:”1″,”broker”:”212b12a2.a8c08e”,”x”:350,”y”:276,”wires”:[[“d2b166e9.2fda58”]]},{“id”:”d2b166e9.2fda58″,”type”:”debug”,”z”:”b9bd2972.30ee88″,”name”:”Show message”,”active”:true,”console”:”false”,”complete”:”true”,”x”:595,”y”:276,”wires”:[]},{“id”:”d4762c5e.b8f34″,”type”:”mqtt out”,”z”:”b9bd2972.30ee88″,”name”:”Publish to /test/topic”,”topic”:”/test/topic”,”qos”:”0″,”retain”:”true”,”broker”:”212b12a2.a8c08e”,”x”:576,”y”:182,”wires”:[]},{“id”:”d8358446.c5e948″,”type”:”inject”,”z”:”b9bd2972.30ee88″,”name”:”Message”,”topic”:””,”payload”:””,”payloadType”:”date”,”repeat”:””,”crontab”:””,”once”:false,”x”:332,”y”:182,”wires”:[[“d4762c5e.b8f34”]]},{“id”:”212b12a2.a8c08e”,”type”:”mqtt-broker”,”z”:””,”broker”:”localhost”,”port”:”1883″,”clientid”:””,”usetls”:false,”compatmode”:true,”keepalive”:”60″,”cleansession”:true,”willTopic”:””,”willQos”:”0″,”willPayload”:””,”birthTopic”:””,”birthQos”:”0″,”birthPayload”:””}]


You now have a small IoT gadget ready to start your own IoT adventure. Later we will look into how we can add more hardware and even interconnect multiple devices, such as sensors and relays.

Many thanx to Taner Yavuz and Maksym Gerasymchuk for the help with this post 🙂

You can also check out my other articles around MQTT:

MQTT for Dummies

MQTT for PIC Microcontrollers




2 thoughts on “MQTT and ActiveMQ on RPI”

Leave a Reply