Difference between revisions of "Automation - Node-Red"
Line 1: | Line 1: | ||
{{{!}} class="wikitable" style="float: right; width: 322px;" border="2" | {{{!}} class="wikitable" style="float: right; width: 322px;" border="2" | ||
{{!}}+ Proven on: | {{!}}+ Proven on: | ||
{{!}}- | {{!}}- --="" debian="" | ||
{{!}} style="text-align: center; width: | {{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 11 (bullseye) | {{!}} style="text-align: center; width: 40px;" {{!}} 11 (bullseye) | ||
{{!}} | {{!}} | ||
<br> | <br> | ||
{{!}}- | {{!}}- --="" lmde="" | ||
{{!}} style="text-align: center; width: 65.675px;" {{!}} [[File:Logo LMDE.png{{!}}60px{{!}}link=https://linuxmint.com/edition.php?id=279{{!}}center{{!}}middle{{!}}frameless]] | {{!}} style="text-align: center; width: 65.675px;" {{!}} [[File:Logo LMDE.png{{!}}60px{{!}}link=https://linuxmint.com/edition.php?id=279{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 4 | {{!}} 4 | ||
{{!}} | {{!}} | ||
<br> | <br> | ||
{{!}}- | {{!}}- --="" linux="" mint="" | ||
{{!}} style="text-align: center; width: 67.5125px;" {{!}} [[File:Logo Mint.png{{!}}60px{{!}}link=https://linuxmint.com{{!}}center{{!}}middle{{!}}frameless]] | {{!}} style="text-align: center; width: 67.5125px;" {{!}} [[File:Logo Mint.png{{!}}60px{{!}}link=https://linuxmint.com{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 19.3 / 20.3 | {{!}} 19.3 / 20.3 | ||
{{!}} | {{!}} | ||
<br> | <br> | ||
{{!}}- | {{!}}- --="" ubuntu="" | ||
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Ubuntu.png{{!}}60px{{!}}link=https://ubuntu.com/{{!}}center{{!}}middle{{!}}frameless]] | {{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Ubuntu.png{{!}}60px{{!}}link=https://ubuntu.com/{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 20.04.3 | {{!}} 20.04.3 | ||
{{!}} <span style="color:#8B0082">issues</span> | {{!}} <span style="color:#8B0082">issues</span> | ||
<br> | <br> | ||
{{!}}- | {{!}}- --="" sparky="" linux="" | ||
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Sparky.png{{!}}60px{{!}}link=https://sparkylinux.org/{{!}}center{{!}}middle{{!}}frameless]] | {{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Sparky.png{{!}}60px{{!}}link=https://sparkylinux.org/{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 5.11 | {{!}} 5.11 | ||
{{!}} | {{!}} | ||
<br> | <br> | ||
{{!}}} | {{!}}} | ||
[https://nodered.org/ Node-Red Web Site] | [https://nodered.org/ Node-Red Web Site] | ||
Line 64: | Line 67: | ||
* <code>sudo wget <nowiki>https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start</nowiki> -O /usr/bin/node-red-start</code> | * <code>sudo wget <nowiki>https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start</nowiki> -O /usr/bin/node-red-start</code> | ||
* <code>sudo wget <nowiki>https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop</nowiki> -O /usr/bin/node-red-stop</code> | * <code>sudo wget <nowiki>https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop</nowiki> -O /usr/bin/node-red-stop</code> | ||
<span style="color:#4B0082">'''Note:'''</span> These 3 files are kinda rpi specific... | <span style="color:#4B0082">'''Note:'''</span> These 3 files are kinda rpi specific... | ||
Line 70: | Line 72: | ||
*<code>sudo vi /lib/systemd/system/nodered.service</code> | *<code>sudo vi /lib/systemd/system/nodered.service</code> | ||
<span style="color:#4B0082">Replace the user name "pi" with a user on your actual system...</span> | <span style="color:#4B0082">Replace the user name "pi" with a user on your actual system...</span> | ||
Revision as of 21:05, 14 January 2022
11 (bullseye) |
| |
4 |
| |
19.3 / 20.3 |
| |
20.04.3 | issues
| |
5.11 |
|
As always...
Start with:
sudo apt update
sudo apt upgrade
Installing Node-Red
Start by installing nodejs and the javascript package manager (npm)
NOTE: The Ubunto repositories serve up an outdated version of Node.js. (v10.19.0)
Node-Red 2 requires v12...
sudo apt install nodejs
sudo apt-get install -y build-essential
sudo npm install npm@latest -g
- (Doesn't actually seem to change anything on Debian... Updates to 8.3.0 on Ubuntu.)
Use npm to install Node-RED
sudo npm install -g node-red
Run it...
node-red
Adding Autostart capability using SystemD
Then download three required files to their correct locations
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
Note: These 3 files are kinda rpi specific...
To run as a user other than Pi, you need to edit the nodered.service file. To edit this use sudo to edit the file /lib/systemd/system/nodered.service
and change the lines 11, 12 and 13.
sudo vi /lib/systemd/system/nodered.service
Replace the user name "pi" with a user on your actual system...
make the two scripts executable
sudo chmod +x /usr/bin/node-red-st*
reload the systemd daemon
sudo systemctl daemon-reload
enable Node-RED to run automatically
sudo systemctl enable nodered.service
Start Node-RED
sudo systemctl start nodered.service
Securing Node-RED
- Username/password based authentication
- The suggested
adminAuth section is already there... edit it
You can create multiple users by duplicating the user object inside users: []
- The suggested
- Command-line Administration(how to get node-red-admin)
Useful management stuff
Learn about the current service status
sudo systemctl status nodered.service
(Re-)Start the Node-RED background service
sudo systemctl restart nodered.service
Stop the Node-RED background service
sudo systemctl stop nodered.service
Disable the Node-RED background service
- sudo systemctl disable nodered.service
Get the service log since the last boot
sudo journalctl -f -u nodered.service -b -o cat
Also
Node-RED can then be started and stopped by using the commands:
node-red-start
and
node-red-stop
Updating
Apparently, just run the install again...
sudo npm install -g node-red
(pretty simple...)
Debugging Node-Red issues
ECONNRESET caused by MQTT
Error: Client network socket disconnected before secure TLS connection was established
Error: read ECONNRESET
Error: read ECONNRESET
Error: Client network socket disconnected before secure TLS connection was established
Hhhmmm...
ECONNREFUSED caused by alexa-home-conf
[error] [alexa-home-conf:919d2660.bd9218] Error: connect ECONNREFUSED 34.240.81.189:8883
Strange response from the creator: https://github.com/hardillb/node-red-contrib-alexa-home-skill/issues/51
Doesn't actually explain what's going on, but it's allegedly harmless. My question is: Why in fuck does it want to connect to a non-functional "alternate endpoint"?
Graceful restarts (maybe)
This is likely not needed when running under systemd...
You can start a script as a daemon. But first install forever
sudo npm install -g --unsafe-perm forever
Then issue command:
forever start /usr/local/lib/node_modules/node-red/red.js
Things to do with Node-RED once it's installed
WIP: These pages will appear as I get things updated from what's on the older wiki...
Some useful Node-Red tips
- Enable / Disable a Flow
- Search: node red function multiple inputs
- Node-Red stores it's data in
~/.node-red
- Palette Export or Backup
Some interesting Node-Red Add-Ons
- Machine learning package for node-red
- node-red-contrib-boolean-logic
- Create "Buffer" from "Invert"
- node-red-contrib-google-home-notify
- node-red-dashboard
- node-red-node-ping
- There seem to be other versions... possibly better...
- node-red-contrib-plex
Moving Node-Red to a new server
When creating a NEW server
Pretty easy actually...
Build the server & install everything as normal.
Then stop the node-red service and replace ~/.npm & ~/node-red with copies from the old server.
When Renaming a server
(i.e.: Moving or cloning a VM...)
Seems to lose the flows. :(
They're not actually lost. :)
The flow files are named with the server name.
You can select a flow file in ~/.node-red/settings.js
Uncomment the line that says: //flowfile: 'flows.json',
and change flows.json to the name of your actual flow file. (in the same folder...)
Then restart node-red
sudo systemctl restart nodered.service
If you are using other services on the server (i.e.: MQTT), you may run into further weirdness like having to tell nodes where to find these services. More research still required on this...