Node-RED is an open-source flow-based programming tool designed to help you connect hardware devices, APIs, and online services.
Being designed for the Internet of Things (IoT), Node-RED is a perfect match for the Raspberry Pi and can be useful for dealing with the Pi’s GPIO.
This software package will allow you to interpret data from your Raspberry Pi’s GPIO pins and create an action based on that data. You can also use Node-RED to interact with the GPIO pins based on an event.
Node-RED on Raspberry Pi (https://nodered.org/docs/getting-started/raspberrypi)
build-essentialpackage. This package is used to build any modules that NPM requires.
build-essential:
$ sudo apt install build-essential
Finally, we can install Node-RED by running the following command.
This command will install several things to our Raspberry Pi.
These packages include Node.js, npm, and Node-RED itself:
$ bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
The first prompt asks if you really want to proceed with the installation:
Are you really sure you want to do this ? [y/N] ?
Type Y and then press ENTER to continue.Would you like to install the Pi-specific nodes ? [y/N] ?
Again to this question, press the letter Y and then press ENTER to continue.
While Node-RED is available through the Raspbian package repository, the script is the officially recommended install method as it also installs npm. npm is incredibly useful as it is a package manager for the javascript programming language that Node-RED is built on. Using npm, you will be able to install additional modules for use with Node-RED.
Reboot
$ node-red
The advantage of starting Node-RED like this is that you have access to its terminal.
You will see things such as errors appear here.
$ sudo systemctl start nodered
If you run into issues with Node-RED not starting correctly on your Raspberry Pi, we recommend trying the other method.
$ sudo systemctl status nodered
This command will give you various details about Node-RED and should let you know whether it is successfully running as well as the last few lines it outputted to the terminal.
hostname -Ion the Pi.
http://[IPADDRESS]:1880
If everything is working correctly, you should now be greeted Welcome to Node-RED!.
$ sudo systemctl enable nodered
Alternatively, if you want to stop Node-RED from automatically starting on boot,
you can make use of the following command:
$ sudo systemctl disable nodered
### ADDITIONAL RECOMMENDATIONS ###
- Remove the /etc/sudoers.d/010_pi-nopasswd file to require entering your password
when performing any sudo/root commands:
sudo rm -f /etc/sudoers.d/010_pi-nopasswd
- You can customise the initial settings by running:
node-red admin init
- After running Node-RED for the first time, change the ownership of the settings
file to 'root' to prevent unauthorised changes:
sudo chown root:root ~/.node-red/settings.js
If you are interested in learning more about how to use Node-RED
we recommend checking out the
official guide on
creating your first Node-RED flow
(Node-RED docs).
$ cd ~/.node-red
$ npm install node-red-dashboard
Node-RED dashboard can be access via http://192.168.xxx.xxx:1880/ui,
however the path /ui is disabled by default, we need to change the setting at settings.js.
Use nano editor to make the change:
$ nano settings.js
Press ctrl-w or simple scrolling down to search for line with ui: { path: "ui" } and uncomment out
the line by deleting the // in front of the line. Pressed ctrl-x to save the file.
If you had configured to run Node-RED as a daemon service (i.e. auto-run at boot up),
you will need to restart the node-red for the change to take on effect:
$ sudo systemctl restart nodered
But if you are running node-RED manually, you can ignore this restart command. Now let's create our dashboard.
You will noticed that there is an newly installed Dashboard
category on the node palette,
these are the UI widgets can be displayed on the Dashboard.