Node-RED
#1
Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways. It build on top of Nodejs

With this, PINE64 going to be more interesting.   Smile

Tested with PINE64 2GB(1GB and 512MB shall work well, anyone with this please help to test out), Debian Base(Others Debian built shall work well, some Debian only support Nodejs 4.x).

1) Install Nodejs
sudo su

cd /home/debian
mkdir src
cd 
wget https://nodejs.org/dist/latest-v6.x/node...m64.tar.gz
tar -xvf node-v6.8.1-linux-arm64.tar.gz
cd node-v6.8.1-linux-arm64

sudo cp -R * /usr/local/
cd ..
rm -rf node-v6.8.1-linux-arm64


2) Install Node-Red
sudo npm cache clean
sudo npm install -g --unsafe-perm  node-red


3) Boot time auto start
a) Create bash file for node-red service
sudo nano /lib/systemd/system/nodered.service
Code:
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool.
Wants=network.target
Documentation=http://nodered.org/docs/

[Service]
Type=simple
# Run as normal debian user - feel free to change...
User=debian
Group=debian
WorkingDirectory=/home/debian
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=128"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target
b) Create bash file to start node-red
sudo nano /usr/bin/node-red-start
Code:
#!/bin/bash
echo -e '\033]2;'Node-RED console'\007'
nv=`node -v | cut -d "." -f1`
if [ "$nv" = "v0" ]; then
   echo -e "\033[0;47m                                                  \033[0m"
   echo -e "\033[0;47m    node.js v0.10 is NO LONGER supported.         \033[0m"
   echo -e "\033[0;47m    please consider upgrading to node.js LTS.     \033[0m"
   echo -e "\033[0;47m                                                  \033[0m"
   echo -e "\033[0;47m    you can do this with the following command:   \033[0m"
   echo -e "\033[0;47m        update-nodejs-and-nodered                 \033[0m"
   echo -e "\033[0;47m                                                  \033[0m"
   echo -e " "
fi
HOSTIP=`hostname -I | cut -d ' ' -f 1`
if [ "$HOSTIP" = "" ]; then
   HOSTIP="127.0.0.1"
fi
echo -e "Start \033[1m\033[38;5;88mNode-RED\033[0m"
echo " "
echo "Once Node-RED has started, point a browser at http://$HOSTIP:1880"
echo "On Pine64 Node-RED works better with the Firefox browser"
echo " "
echo -e "Use   \033[0;36mnode-red-stop\033[0m                          to stop Node-RED"
echo -e "Use   \033[0;36mnode-red-start\033[0m                         to start Node-RED again"
echo -e "Use   \033[0;36mnode-red-log\033[0m                           to view the recent log output"
echo -e "Use   \033[0;36msudo systemctl enable nodered.service\033[0m  to autostart Node-RED at every boot"
echo -e "Use   \033[0;36msudo systemctl disable nodered.service\033[0m to disable autostart on boot"
echo " "
echo "To find more nodes and example flows - go to http://flows.nodered.org"
if [ "$nv" = "v0" ]; then
   echo "You may also need to install and upgrade npm"
   echo -e "      \033[0;36msudo apt-get install npm\033[0m"
   echo -e "      \033[0;36msudo npm i -g npm@2.x\033[0m"
fi
sudo service nodered start
echo " "
sudo journalctl -f -n 0 -u nodered -o cat

c) Create bash file to stop node-red
sudo nano /usr/bin/node-red-stop
Code:
#!/bin/bash
echo -e '\033]2;'Node-RED console'\007'
echo -e "\033[1mStop \033[38;5;88mNode-RED\033[0m"
echo " "
echo -e "Use   \033[0;36mnode-red-start\033[0m   to start Node-RED again"
sudo service nodered stop
echo " "
exit

d) reload systemctl daemon
sudo systemctl daemon-reload
e) create auto start link
 sudo systemctl enable nodered.service
4) Start Node-red without reboot
sudo systemctl start nodered.service
5) View node-red log:
sudo journalctl -f -u nodered -o cat 
6) Configure node-red settings and install node
After first time start up, node-red will auto created a system folder at /home/debian/.node-red
To configure the setting, /home/debian/.node-red/settings.js
To install node, /home/debian/.node-red/node_modules
Default setting node-red will use PINE64 host name to generate flow file. /home/debian/.node-red/flows_pine64.json
If you will change host name, update the "flowFile" path in settings.js
a) to generate password protected
npm install -g node-red-admin
node-red-admin hash-pw
(Enter your password, it will return encoded password string, copy this string)

b) Famous Dashboard UI
npm install node-red-dashboard

c) Useful scheduler node
npm install node-red-contrib-bigtimer


There are thousand of node & flow at here.

after install new node, restart node-red.
sudo systemctl restart nodered.service

7) After all done, you will able to access node-red at browser (Default will use port 1880, can be update in settings.js)
http://[PINE64-IP-Address]:1880
   

8) Create a sample flow. You can import the this sample flow at Menu(Right Top Corner) -> Import -> Clipboard
Code:
[{"id":"60ba3a72.b24c54","type":"ui_button","z":"5bd1466.b4e63b8","name":"","group":"7e934c94.882ef4","order":0,"width":0,"height":0,"label":"Click Me!","color":"","icon":"","payload":"","payloadType":"str","topic":"","x":188,"y":93,"wires":[["529c0ec4.837a7"]]},{"id":"529c0ec4.837a7","type":"function","z":"5bd1466.b4e63b8","name":"","func":"var d = new Date();\nmsg.payload = d;\nreturn msg;","outputs":1,"noerr":0,"x":326,"y":90,"wires":[["29ee44ea.ad52ec"]]},{"id":"29ee44ea.ad52ec","type":"ui_text","z":"5bd1466.b4e63b8","group":"7e934c94.882ef4","order":0,"width":0,"height":0,"name":"","label":"Current Date","format":"{{msg.payload}}","layout":"row-spread","x":542,"y":95,"wires":[]},{"id":"7e934c94.882ef4","type":"ui_group","z":"","name":"Hello PINE64","tab":"1680a81f.a5aec8","disp":true,"width":"6"},{"id":"1680a81f.a5aec8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
   

9) This sample flow using node-red-dashboard, you can access the UI at http://[PINE64-IP-Address]:1880/ui/#/0
   

Hope you guy enjoy this.  Big Grin Big Grin  Have fun!!!
#2
Thank you. I fixed your 7) bullet point.

(it had a mistaken "frown face" due to a misplaced colon)
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#3
(10-15-2016, 09:08 AM)MarkHaysHarris777 Wrote: Thank you.  I fixed your 7) bullet point.  

(it had a mistaken "frown face" due to a misplaced colon)

Thanks Mark.  Smile
#4
The Node-Red Documentation is linked to the left.
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
#5
Install Mosquitto (MQTT) 

Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "Internet of Things" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.

1) Install
sudo apt-get update

sudo apt-get install mosquitto

2) Configure Password
cd /etc/mosquitto/

mosquitto_passwd -c [output file name] [your username]
[your password]

sudo nano mosquitto.conf
Append this string at the bottom of the file.
Code:
password_file /etc/mosquitto/mqttPINE64pass


3) Manually Start/Stop (Default Auto Start)

sudo /etc/init.d/mosquitto start
sudo /etc/init.d/mosquitto stop


4) Receive and send from Node-Red
   
#6
Awesome guide!

Thanks!  

I would suggest one minor addition/edit to step 1:
(10-15-2016, 08:55 AM)klliew Wrote: cd /home/debian
mkdir src
cd

IMPORTANT:  You must update the file names below.  To update them, get the current link by going to https://nodejs.org/en/download/ and copying the link labeled Linux Binaries(ARM) --> ARMv8.  Make sure that you update the bolded text to match the current file.

wget https://nodejs.org/dist/latest-v6.x/node-v6.8.1-linux-arm64.tar.gz[/i]
tar -xvf node-v6.8.1-linux-arm64.tar.gz
cd node-v6.8.1-linux-arm64

sudo cp -R * /usr/local/
cd ..
rm -rf node-v6.8.1-linux-arm64


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Node-RED neeeds 0 3,258 07-07-2018, 07:58 PM
Last Post: neeeds
  Mesh node Madroxprime 1 5,393 09-30-2017, 07:08 PM
Last Post: Mpoint

Forum Jump:


Users browsing this thread: 1 Guest(s)