In this tutorial we are going to install Node-Red into our Ubuntu server which is running the Mosquitto broker. This will enable us to use a web interface to access and control the flow of the messages.
Starting with our freshly installed Ubuntu and Mosquitto we first need to install the NodeJs 12.x
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt update sudo apt install yarn sudo apt-get install -y nodejs
Now we will test taht the NodeJS is working correctly and is the correct version with the command:
The -v switch will return the version of the installed NodeJS software, you should get a version number starting with 12. something. If this is working then we install Node-Red it’s self:
sudo npm install -g --unsafe-perm node-red
Go grab a coffee or coke as this can take a little while, especially on slower machines. Once complete we will try to run the Node-Red program as a test with the following command:
if all goes well you will see the version numbers and an ip address and port like 127.0.0.1:1800. However if we reboot the computer NodeRed will not run automatically at startup, to solve this we need to create a service which will be used to start Node-Red at startup.
Start by opening up a blank file to use as our service file:
sudo nano /etc/systemd/system/node-red.service
Copy and paste in the following to this file:
[Unit] Description=Node-RED After=syslog.target network.target [Service] ExecStart=/bin/node-red-pi --max-old-space-size=128 -v Restart=on-failure KillSignal=SIGINT # log output to syslog as 'node-red' SyslogIdentifier=node-red StandardOutput=syslog # non-root user to run as WorkingDirectory=/home/sammy/ User=sammy Group=sammy [Install] WantedBy=multi-user.target
Press CTRL-O – ENTER – CTRL-X to save and exit nano text editor
Now we enable the service with the following command
sudo systemctl enable node-red
To start the service run:
sudo systemctl start node-red
To stop the service run:
sudo systemctl stop node-red
from our command line enter the command
Look for the IP address of your server in my case it is 10.1.1.105 so I will use this in our example. Go to another machine on the network and open your browser (I use firefox) to the address of your broker and port 1880, for example “10.1.1.105:1880” this will open up node red and you can now start using it. You will also find a display console at “10.1.1.105:1880/ui” in my example
However I just get the message “CANNOT get /ui” at this stage, but we can use it later.
This tutorial was based on “How to Connect Your Internet of Things with Node-RED on Ubuntu 16.04“