Install node-red
Video: Astrobox with relays and contactor - turn on/off 3D printer and lights
This is the electrical scheme:
We must activate ssh, to do this on the sd card with our Astrobox / Astrotouch system (with the Raspberry turned off, the card is extracted and inserted into a PC) we create a folder called “ssh” in the root.
We reintroduce the card to the Raspberry and restart.
From the terminal on Linux or MacOS, and installing Putty on a Windows system, we access our Astrobox / Astrotouch by ssh.
ssh pi@192.168.1.173
The default password is “raspberry” for the user “pi”.
In the terminal, we’ll get the latest system’s package list onto our Raspberry Pi using the following command:
sudo apt-get update
sudo apt-get full-upgrade
sudo apt install build-essential git curl
Install node-red with this script:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
When running the script, we’ll be asked two questions: Would you like to continue, and would you like to install a collection of Pi-specific nodes. Please enter: “Y”, (Yes) for both prompts:
Y
After we’ll activate the service:
sudo systemctl enable node-red.service
Now, we’ll copy the app.jinja2 file to the local (our computer):
scp pi@192.168.1.173:/AstroBox/src/astroprint/templates/app.jinja2 /Users/myuser/Astroprint
(Root in your computer is different)
After modification we’ll copy to Astrobox/Astroprint (IP address can be different):
scp app.jinja2 pi@192.168.1.173:/home/pi
The next step we have to replace the file in “templates” folder:
sudo cp app.jinja2 /AstroBox/src/astroprint/templates
We can modify app.jinja2 in the terminal, too:
sudo nano /AstroBox/src/astroprint/templates/app.jinja2
We’ll add these lines to app.jinja2 code after the line “<li><a href="#"><i class="icon-th"></i> Dashboard</a></li>
”:
<li><a href=":1880/ui/#!/0?socketid=SJg0e6_hDUHhFuzJAAAA"><i class="icon-off"></i> Local PSU</a></li>
<li><a href="http://YOURDOMAIN.duckdns.org:1880/ui/#!/0?socketid=SJg0e6_hDUHhFuzJAAAA"><i class="icon-off"></i> Internet PSU</a></li>
Remember: We have to change the socketid with our own id flow project.
To install in Node-red the stable version of nodes use the “Menu - Manage palette” option and “search” for node-red-dashboard or in the terminal:
npm i node-red-dashboard
To install the stable version use the Menu - Manage palette option and search for node-red-node-pi-gpio or in the terminal:
npm i node-red-node-pi-gpio
Inside node-red (http://MY-ADDRESS-IP:1880
), we follow the path “menu - import” and paste the following code:
[
{
"id": "e4e93229cafed0d3",
"type": "tab",
"label": "AstroBox",
"disabled": false,
"info": "",
"env": []
},
{
"id": "8a79a736e8e81e48",
"type": "rpi-gpio out",
"z": "e4e93229cafed0d3",
"name": "3D Printer",
"pin": "20",
"set": false,
"level": "1",
"freq": "",
"out": "out",
"bcm": true,
"x": 490,
"y": 320,
"wires": []
},
{
"id": "3498bd34dc199839",
"type": "rpi-gpio out",
"z": "e4e93229cafed0d3",
"name": "Lights",
"pin": "21",
"set": true,
"level": "1",
"freq": "",
"out": "out",
"bcm": true,
"x": 460,
"y": 400,
"wires": []
},
{
"id": "dea4e916dd867a22",
"type": "ui_switch",
"z": "e4e93229cafed0d3",
"name": "3D Printer",
"label": "3D Printer",
"tooltip": "",
"group": "021cb03379cc21b4",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"x": 190,
"y": 340,
"wires": [
[
"8a79a736e8e81e48",
"5b6e765e72bfb9e9"
]
]
},
{
"id": "dcb56cbdb521e066",
"type": "ui_switch",
"z": "e4e93229cafed0d3",
"name": "Lights",
"label": "Lights",
"tooltip": "",
"group": "021cb03379cc21b4",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"x": 220,
"y": 420,
"wires": [
[
"3498bd34dc199839",
"5b6e765e72bfb9e9"
]
]
},
{
"id": "5b6e765e72bfb9e9",
"type": "ui_template",
"z": "e4e93229cafed0d3",
"group": "7d2491e702d64557",
"name": "",
"order": 2,
"width": 0,
"height": 0,
"format": "<p><a title=\"Local back\" href=\"http://YOURIP\"><strong>Local Back </strong></a></p>\n<p> </p>\n<p> </p>\n<p><strong><a title=\"Internet back\" href=\"http://YOURDOMAIN.duckdns.org:8087\">Internet Back </a></strong></p>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"x": 540,
"y": 560,
"wires": [
[]
]
},
{
"id": "021cb03379cc21b4",
"type": "ui_group",
"name": "Switch",
"tab": "05d5cd8a2cf044a1",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "7d2491e702d64557",
"type": "ui_group",
"name": "Back",
"tab": "4d278462a4e0afb8",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "05d5cd8a2cf044a1",
"type": "ui_tab",
"name": "PSU",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "4d278462a4e0afb8",
"type": "ui_tab",
"name": "Back to Dashboard",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
OPTIONAL STEP:
A recommended process if we want to have access from the internet is to create and have an active ddns. We have decided to use duckdns (https://duckdns.org) which is a free service. We’ll write these commands in the terminal:
mkdir duckdns
cd duckdns
nano duck.sh
echo url="https://www.duckdns.org/update?domains=**YOURDOMAIN**&token=**YOURTOKEN**&ip=" | curl -k -o ~/duckdns/duck.log -K -
chmod 700 duck.sh
crontab -e
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
./duck.sh
cat duck.log
sudo service cron start
Now, we’ll can access to Astrobox/astroprint from this url:
http://**YOURDOMAIN**.duckdns.org
In our router we have to open the ports corresponding to the IP of our Raspberry to access the domain, in our case we have redirected the service to port 8087. Also for Node-red we have to open port 1880.
http://**YOURDOMAIN**.duckdns.org:8087
We restart our Raspberry and we will be able to enter our Node-red environment:
http://**YOURDOMAIN**.duckdns.org:1880
I hope this tutorial can help you.