Node-RED on BBB

This chapter describes the installation of Node-RED on a BeagleBone Black including the use of the IO's. If the IO's of a SBC are not required, it is recommended to install NodeRED via a Docker image on a PC to play with.

Preconditions

There are no node or npm packages needed from Debian repos, so first remove leftover nodejs stuff and apt installed packages from the Linux directories:

~# npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm
~# apt-get remove npm nodejs

Be sure to install needed packages for building nodejs:

~# apt-get install curl build-essential

Then add deb.nodesource.com to apt repository and install nodejs 8:

~# curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
~# apt-get install nodejs

Now configuration of npm is necessary to install packages globally into user directory. Login as user who later runs nodejs and download the nosudo script:

debian@pc:~/$ cd
debian@pc:~/$ wget https://raw.githubusercontent.com/glenpike/npm-g_nosudo/master/npm-g-nosudo.sh

Execute script and .bashrc:

debian@pc:~/$ chmod +x npm-g-nosudo.sh
debian@pc:~/$ ./npm-g-nosudo.sh
debian@pc:~/$ source ~/.bashrc

Now you are able to install needed npm packages as user globally:

debian@pc:~/$ npm install -g <some package>

Installation

The “Node-RED graphical event wiring tool” called node-red must be installed for having the web based wiring tool on bbb:1880 as far as some node-red nodes for accessing the GPIO of the beagle bone black:

debian@pc:~/$ npm i node-red -g
debian@pc:~/$ npm i beaglebone-io johnny-five node-red-contrib-gpio -g

Integrate node-red into systemd by creating a /lib/systemd/system/nodered.service with following content:

~# systemd service file to start Node-RED
[Unit]
Description=Node-RED graphical event wiring tool.
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html
[Service]
Type=simple
# Run as debian user with group gpio in order to have access to gpio pins
User=debian
Group=debian
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=128"
Environment="NODE_RED_OPTIONS=-v"
ExecStart=/usr/bin/env /home/debian/.npm-packages/bin/node-red $NODE_OPTIONS $NODE_RED_OPTIONS
KillSignal=SIGINT
Restart=on-failure
SyslogIdentifier=Node-RED
[Install]
WantedBy=multi-user.target

Enable service:

~# systemctl daemon-reload
~# systemctl enable nodered.service

Show loggings of node-red:

~# journalctl -fu nodered.service -b

Previous Post Next Post