Node-RED - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: PINE A64(+) (https://forum.pine64.org/forumdisplay.php?fid=4) +--- Forum: Pine A64 Projects, Ideas and Tutorials (https://forum.pine64.org/forumdisplay.php?fid=19) +--- Thread: Node-RED (/showthread.php?tid=2395) |
Node-RED - klliew - 10-15-2016 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. 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-v6.8.1-linux-arm64.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 sudo nano /usr/bin/node-red-start Code: #!/bin/bash c) Create bash file to stop node-red sudo nano /usr/bin/node-red-stop Code: #!/bin/bash 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. Have fun!!! RE: Node-RED - MarkHaysHarris777 - 10-15-2016 Thank you. I fixed your 7) bullet point. (it had a mistaken "frown face" due to a misplaced colon) RE: Node-RED - klliew - 10-15-2016 (10-15-2016, 09:08 AM)MarkHaysHarris777 Wrote: Thank you. I fixed your 7) bullet point. Thanks Mark. RE: Node-RED - MarkHaysHarris777 - 10-15-2016 The Node-Red Documentation is linked to the left. RE: Node-RED - klliew - 10-15-2016 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 RE: Node-RED - SvdSinner - 12-14-2016 Awesome guide! Thanks! I would suggest one minor addition/edit to step 1: (10-15-2016, 08:55 AM)klliew Wrote: cd /home/debian |