meta data for this page
  •  

Node-RED on BBB

This chapter describes the installation of Node-RED on a BBB including the use of the IO's.

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:

guest:~$ su
~# 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 buildingnodejs:

~# 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:

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

Execute script and .bashrc:

guest:~$ chmod +x npm-g-nosudo.sh
guest:~$ ./npm-g-nosudo.sh
guest:~$ source ~/.bashrc

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

guest:~$ 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:

guest:~$ npm i node-red -g
guest:~$ 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