Setting up MQTT on RasPi with Node Red

Download and install Raspian Stretch Lite onto RasPi SD card

  • sudo raspi-config
    • Enable SSL and any other desired options

Connect remotely using Putty:

Connect via SSH to the Pi’s IP address

Update and install all of the necessary software:

sudo raspi-update
sudo reboot

after the reboot, log in and install Node-Red

sudo apt-get install nodered

Once installed, we will need to start Node Red by running the following code.

node-red-start

Now you can go to the Pi’s IP address in any web browser but be sure to add port 1880 to the IP address like so:

http://192.168.1.32:1880

Now we want to make it so Node RED runs on startup.

sudo systemctl enable nodered.service

install MQTT support

sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo apt-get update
sudo apt-get -y install mosquitto mosquitto-clients python-mosquitto

Test by starting the service

sudo /etc/init.d/mosquitto start

open a new Putty terminal

In the first terminal enter the following:

mosquitto_sub -d -t hello/world

In the second Window, enter:

mosquitto_pub -d -t hello/world -m "Hellow from Terminal 2!"

If successful, the packet sent from terminal window 2 should appear in window.

One thought on “Setting up MQTT on RasPi with Node Red”

  1. Great tutorial. Notes that helped me as a n00b:

    1. After installing raspbian/raspbian lite, and before ejecting the disk, you can create a blank file in the boot partition called “ssh” to enable access with the password “raspberry.”
    2. To install python support I followed these steps: https://theembeddedlab.com/tutorials/install-mosquitto-on-a-raspberry-pi/

    Everything else worked like a charm…
    Helpful links for fellow learners:
    https://www.raspberrypi.org/documentation/remote-access/ssh/
    https://medium.com/@danidudas/install-raspbian-jessie-lite-and-setup-wi-fi-without-access-to-command-line-or-using-the-network-97f065af722e

Comments are closed.