Instalare pe Debian
Se descarca si executa scriptul de instalare si se instaleaza NodeJS:
sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg NODE_MAJOR=20 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list sudo apt-get update && sudo apt-get install nodejs -y
Verificarea versiunii si instalarea Node-RED:
node -v apt install -y build-essential libssl-dev npm install -g --unsafe-perm node-red
Node-RED porneste cu:
node-red -v
Instalare pe Raspberry Pi
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) systemctl enable nodered.service
Se reporneste sistemul.
Node Red ca serviciu pe Debian
Se creeaza fisierul node-red.service:
nano /etc/systemd/system/node-red.service
Se introduce urmatorul continut:
# This script work on any system using systemd as the init process. # It works on Debian/Raspbian Jessie. # If you have Debian/Rapbian Wheezy and want to use this script with systemd # follow the information here : https://wiki.debian.org/systemd # To easily download, install and set at startup: # wget -O /tmp/download https://gist.github.com/Belphemur/3f6d3bf211b0e8a18d93/download && sudo tar -zxf /tmp/download –strip-components 1 -C /etc/systemd/system/ && sudo systemctl –reload-daemon && sudo systemctl enable Node-RED # To consult the log : journalctl -u Node-RED [Unit] Description=Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways. After=syslog.target network.target Documentation=http://nodered.org/ [Service] #Environment=”NODE_OPTIONS=–max-old-space-size=128″ #Environment=”NODE_RED_OPTIONS=-v” #Full Path to Node.js ExecStart=/usr/bin/node-red WorkingDirectory=/root/.node-red/ # User/Group that launches node-RED (it’s advised to create a new user for Node-RED) # You can do : sudo useradd node-red # then change the User=root by User=node-red User=root Group=root Nice=10 SyslogIdentifier=Node-RED StandardOutput=syslog # Make Node-RED restart if it fails Restart=on-failure # Node-RED need a SIGINT to be notified to stop KillSignal=SIGINT [Install] WantedBy=multi-user.target
Apoi:
systemctl daemon-reload systemctl enable node-red.service systemctl start node-red.service
Securizarea Node Red
In folderul unde este instalat Node Red se instaleaza node-red-admin:
cd ~/.node-red npm install -g node-red-admin
Se genereaza hash-ul parolei:
node-red-admin hash-pw
Se introduce parola si se genereaza hash-ul care se copie si se introduce în settings.js:
Se deschide fisierul settings.js:
cd ~ nano /.node-red/settings.js
In sectiunea Securing Node-RED se activeaza proprietatile adminAuth:, https: si requireHttps: true.
In campul adminAuth se inlocuieste hash-ul parolei cu cel generat anterior cu node-red-admin. Se pot crea si alti utilizatori cu hash-urile parolelor generate ca mai sus. Inregistrarile specifice fiecarui utilizator trebuie sa fie despartite cu virgula:
adminAuth: {
type: „credentials”,
users: [{
username: „admin”,
password: „$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6”,
permissions: „*”
},
{
username: „elvis”,
password: „$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6”,
permissions: „*”
}]
},
adminAuth: {
type: "credentials",
users: [{
username: "elvis",
password: "$2b$08$DxruI/77sJFfLFN0SmO.8ee5SH5wNoi3fPjbLxBwUlQTu85bq",
permissions: "*"
}]
},
În campul https: se completeaza calea până la certificatele Let’s Encrypt:
https: {
key: fs.readFileSync(‘/etc/letsencrypt/live/silviamarin.ro/privkey.pem’),
cert: fs.readFileSync(‘/etc/letsencrypt/live/silviamarin.ro/cert.pem’)
/** Option 1: static object */
https: {
key: require("fs").readFileSync('/etc/letsencrypt/live/silviamarin.ro/privkey.pem'),
cert: require("fs").readFileSync('/etc/letsencrypt/live/silviamarin.ro/cert.pem')
},
Pentru securizarea paginii statice generate de Node Red se activeaza httpNodeAuth: si httpStaticAuth: unde se inlocuieste „user” si hash-ul parolei utilizatorulu respectiv. În ambele campuri trebuie sa fie acelasi utilizator;
httpNodeAuth: {user:”elvis”,pass:”$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6″},
httpStaticAuth: {user:”elvis”,pass:”$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6″},
/** To password protect the node-defined HTTP endpoints (httpNodeRoot),
* including node-red-dashboard, or the static content (httpStatic), the
* following properties can be used.
* The `pass` field is a bcrypt hash of the password.
* See http://nodered.org/docs/security.html#generating-the-password-hash
*/
httpNodeAuth: {user:"elvis",pass:"$2b$08$DxruI/77sJFfLFN0SmO.8ee5SH5wNoi3fPjbLxBwUlQTu85bq"},
httpStaticAuth: {user:"elvis",pass:"$2b$08$DxruI/77sJFfLFN0SmO.8ee5SH5wNoi3fPjbLxBwUlQTu85bq"},
Se salveaza fisierul settings.js si se reporneste Node Red
Accesul la Node Red se face la adresa:
https://silviamarin.ro:8800 (editorul)
sau
https://silviamarin.ro:8800/ui (pagina statica)
Suplimentar
Pentru captura imaginilor de pe camerele de supraveghere trebuie instalat ffmpeg:
apt-get install ffmpeg -y
Pentru captura video de pe camerele de supraveghere trebuie instalat video4linux2:
apt-get install v4l-utils -y
Pentru captura imaginilor de pe webcam-uri USB trebuie instalat fswebcam:
apt-get install fswebcam -y
Pentru NVR se creeaza folderele necesare:
mkdir /mnt/DIVERSE mkdir /mnt/DIVERSE/CAM/ mkdir /mnt/DIVERSE/CAM/camPOARTA mkdir /mnt/DIVERSE/CAM/camCURTE mkdir /mnt/DIVERSE/CAM/camHOL chmod 777 -R /mnt && chown -R nobody:nogroup /mnt
Dupa instalarea pe server a SQLite si InfluxDB se instaleaza nodurile suplimentare in Node-Red:
node-red-dashboard
node-red-node-sqlite
node-red-contrib-bigtimer
node-red-contrib-tradfri
node-red-node-pushbullet
node-red-contrib-pushsafer
node-red-node-email
node-red-node-darksky
node-red-contrib-web-worldmap
node-red-node-geofence
node-red-contrib-moment
node-red-contrib-google-sheets
node-red-node-mysql
node-red-contrib-influxdb
node-red-contrib-dashboard-average-bars
node-red-contrib-throttle
node-red-contrib-chronos
node-red-contrib-fs
Pentru tradfri trebuie instalate pachetele CoAP:
cd /root/.node-red apt-get install libtool git build-essential autoconf automake git clone --recursive https://github.com/obgm/libcoap.git cd libcoap git checkout dtls git submodule update --init --recursive ./autogen.sh ./configure --disable-documentation --disable-shared make make install
Calea pentru CoAP va fi:
/root/.node-red/libcoap/examples/coap-client