MQTT & Node-Red Setup

In the first part, I will go over how to setup an MQTT server, verify it’s working, and also install the node red server.

Part number Quantity
Raspberry Pi model 3B+ 1

A Raspberry Pi model 3B+ will be used. Due to the low processing power needed, an older version of the raspberry can be used as well. I had access to a model 3B+ so the tutorial is written around that version.

You will need to have direct access to the raspberry pi. This can be with a mouse/keyboard/monitor or SSH access.

Once you have access to the raspberry pi, open a terminal and type or copy/paste the following command:

sudo apt-get install mosquitto mosquitto-clients

This will install the MQTT server. To verify the installation was successful and the server is indeed running, open up another terminal.

In the first terminal, enter this command:

mosquitto_sub -d -t test

in the second terminal, enter this command:

mosquitto_pub -d -t test -m "Hello world"

if the server is working, you’ll be greeted with a “Hello world” in the first terminal.

To install node-red, copy/paste the following command:

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

Once the installation is done, enter the following command to start up the server on every boot:

sudo systemctl enable nodered.service

For now, enter the following to start up the server:

node-red-start

If the server is running, you can access it by going to http:\\ipaddress:1880


Node Red Homepage

Next, verify that the mqtt server can be seen by node-red. Do this by placing a “mqtt-in” block. Double click on it and you’ll see the option add a new mqtt-broker.


MQTT Settings

Click on the pencil icon to the right of it and enter in “localhost” in the server field. This is because the mqtt server and node red are running on the same machine. Once done, click on Add.


MQTT Settings

Under Topic, enter in anything as a dummy value. This will be changed in Part 4. Next, click Done followed by Deploy to publish the changes.


MQTT Settings

If it connects, you’ll be greeted with a green square next to “connected”


MQTT Connection Status

Please stay tuned for part 2 where I will go over how to log data to Google Sheets. Thanks for reading!