In this guide I will show you a quick, easy an pretty straight-forward way to install Mosquitto and Node-RED onto a Raspberry Pi running Raspberry Pi OS.
Install Mosquitto MQTT-broker
sudo apt install -y mosquitto mosquitto-clients
sudo vim /etc/mosquitto/mosquitto.conf
Add following lines at end:
listener 1883
allow_anonymous true
Enable and start mosquitto
sudo systemctl enable --now mosquitto
Test receiving of MQTT-messages
mosquitto_sub -d -t testTopic
Install Node-RED
On your Raspberry open a terminal and enter following lines to download and install Node-RED
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
Now we need to enable and start Node-RED
sudo systemctl enable --now nodered
Install Node-RED dashboard
node-red-stop
cd ~/.node-red
npm install node-red-dashboard
Now we test to access Node-RED from another machine on the same network by opening a web-browser and access following URL:
http://[RasperryPi_IP]:1880
Whether you cannot access your Node-RED dashboard most likely your firewall is blocking to access it remotely. So we install and configure the Ubuntu firewall-tool ufw
sudo apt install ufw
ufw allow 1880
ufw allow 1883
sudo ufw enable
Configure Node-RED
You should now be up and running and able to add an mqtt-in node via your Node-RED dashboard and configure your MQTT-broker with URL 127.0.0.1:1883