-
Notifications
You must be signed in to change notification settings - Fork 1
Setup a RaspberryPI to run node red
I have gotten a few questions on how to get the RaspberryPI up and running so I figured to collect the information here.
- A RaspberryPI, BananaPI or other compatible version (must have GPIO)
- An micro-SD card, at least 16 GB (but I recommend 32 GB) and Speed Class 10 (UHS Speed Class 3) and an adapter so that you can run it in a computer
- A monitor with HDMI (and a micro-HDMI adapter if you are using RaspberryPI 4)
- A wired mouse and keyboard, or a wireless with USB "dongle"
- A relay board for RaspberryPI
- Optional: Temperature sensors
Before we start it we have to get the Raspian OS over to the SD card:
- Step 1: Download and Install Raspberry Pi Imager: https://www.raspberrypi.org/software/
- Step 2: Run Raspberry Pi Imager and Format the SD Card
- Step 3: Burn the Raspberry Pi OS Image to the SD Card
Easy as that, but else read the instructions here: https://youtu.be/ntaXWS8Lk34 and check the video https://youtu.be/ntaXWS8Lk34
Insert the SD card into the SD card slot (on the underside, normally, of the RaspberryPI).
Connect the monitor using HDMI to the RaspberryPI and the mouse and keyboard (or through the USB dongle) and then plugin the USB charger/Power and wait for it to boot up.
Start by updating your OS, so open a terminal and execute the two update commands:
sudo apt-get update
sudo apt-get upgrade
Next thing I do is to enable SSH, VNC and 1-Wire.
You need to setup VNC with a password, and I recommend to go and register an account with RealVNC Connect (or use the free TightVNC) so you can connect to your RaspberryPI from anywhere.
After a restart to enable the services I'd recommend to install FireFox as it runs much lighter on the PI compared to Chrome...
- Open the main menu, and go into Preferences
- Start the "Add / Remove software" tool
- In the search engine, type "firefox-esr"
Give the sudo
password and you'll have Firefox in the "Internet" menu to start.
node-red comes preinstalled in Raspian but we want to upgrade it a bit and set it to auto-start at startup, and enable a password!
Start by checking your node
version, in the terminal: node -v
Anything above 12
is fine, but 16
is preferred!
Execute the following in the terminal to update node-red and install node v16 (if you already have v16 or above you can skip the --node16
flag at teh end):
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node16
Answer "yes" to the questions...
Node-red installs as a Service by default but we want node-red to run when the Pi is turned on, or re-booted, and we can enable the service to autostart by running the command:
sudo systemctl enable nodered.service
To disable the service (if you want to remove it), run the command:
sudo systemctl disable nodered.service
I strongly recommend to follow the guide here, https://nodered.org/docs/user-guide/runtime/securing-node-red, to setup HTTPS and securing the HTTP nodes. However, if you are only going to use the Pi in your own home network it's not really that important... If you setup HTTPS, also enable it to run Let’s Encrypt
which automatically (and securely) keeps your certificates up to date (Guide: https://pimylifeup.com/raspberry-pi-ssl-lets-encrypt/).
You should setup a password for node-red though!
Before we can edit the password we must start node-red first so that it creates the settings
file for us, execute:
node-red-start
Once it has started hit [CTRL+C] to stop it and then execute vi ~/.node-red/settings.js
(If you haven't used vi
before, you are in for a treat... It works in mysterious ways, first you are in "read-only" mode and only a few keys works as "actions" but you can always hit [Esc] key to get back to "read-only" if you get out of it and typing :q
(or :q!
) exits vi
)
Use the arrow keys to find this section:
Use the arrow keys to "step" to the first /
as shown in the picture and then hit the x
key (delete in vi
) twice. Move down one row and remove the rest all the way down:
Now to ensure you are in "read mode" hit [Esc] and then hit :wq
(where colon :
sets you in "command mode" and w
is "write/save" and q
is "quit")
Back in the terminal execute: node-red admin hash-pw
It'll ask you for the password and show you the hash for it. Copy the hash to the clipboard (including the dollar sign).
Open vi
again (you can hit the up-arrow in the terminal to step through the history of commands).
Go down to the same section an x
aways the whole old password so only ""
remains. Set the cursor on the first "
, hit i
(for "insert") and then paste ([Shift]+[Insert]) the hash in between the quotation marks. Hit [Esc] and then :wq
again.
(If you mess up, hit [Esc] followed by :q!
to exit out and try again...)
Now execute node-red-restart
and you can open Firefox and paste the URL http://localhost:1880/
which will open the Node-red GUI, and it should ask you for a password.
Now is a good time to restart your Pi to make sure the node-red starts a new after the reboot!
Go to the Code
section and copy the script:
In the node-red GUI, chose "import" from the main menu:
Then paste the flow code (JSON) into the textbox and hit Import:
You'll notice a few errors (but don't worry, we'll remedy these!):
(Depending on if you have added some nodes or payed around your errors might vary!)
If you have "touched" the original Flow (Flow 1) it will import into Flow 2, if so, you can delete Flow 1 if you like, open Flow 1, then from the main menu, select "Flows -> Delete" and it'll be removed. From the same menu you can select to rename the flow with with HT-Control to, e.g. HT-Control
.
Now we need to import some of the missing Nodes, again, from the Main menu, chose "Manage Palette" and then the "Install" tab:
In the search, start typing the names of the missing nodes, e.g. if you chose "Advanced", sensor-ds18b20
, then hit Install:
(And Install again in the "Warning" box).
Repeat the INstall for:
- node-red-dashboard
- node-red-contrib-ui-led
You'll notice the blue dot on the nodes:
This indicates it's a new (or changed) node and it has not yet been deployed (more on that soon).
The nodes with a warning triangle on them we need to address:
These are Dashboard nodes and we have to set the groups to them. Double click on one of them and then the "Edit" pen:
In the next window, hit the "Edit" pen again:
Now hit [Update] all the way back, and finally [Done], continue by double-clicking the next UI node with the triangle on it and do the same. Or, you can use the "Config" view to update the same:
Same there, open the "Edit" pen and Update.
After you have created all the Groups and the Dashboard you can hit the "Deploy" button. You shouldn't get any warnings, but if you do, check the "Config" to figure out what and try to fix 'em.
Now you can open a new Tab in Firefox and hit the URL http://localhost:1880/ui
:
We need to update the node-red config a bit with the Security key for the ENTSOE API.
To avoid having the API Key in our code we use an "environment variable" and there's a few ways to do that but since we run the instance of node-red as a service I opted for using an "environment" file, execute:
sudo vi /etc/environment
(It might be empty and in that case hit i
(insert) instead of o
!)
Hit o
to "open" a new line and then paste your key as this (but replace the X´s of course with your key):
ENTSOE_SECURITY_TOKEN=xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx
Hit [Esc] and then :wq
.
Now restart the Pi and it should all work!
The relay board is controlled by the GPIO node called Relay control
(to the right):
Double-click it to open.
I've set the relay board on the GPIO 17 pin (with the number 11 on the physical board). You also need to grab 5V Power
and Ground
over to the relay board. You can take power and ground from any of the available pins, for example pin 4 for 5V and 9 for Ground.
Then wired them to VCC
(power) and GND
(Ground) as well as to one of the control pins on the relay board.