loading

This Instructable will go over what Node-Red is and how to set it up on the Beaglebone Black (BBB).

On Node-Red's website, they describe it as a tool for wiring together hardware devices, APIs and online services in new and interesting ways. Because of the visual nature of node-red, it also makes IoT coding much more streamlined. You don't need to be a fantastic coder in order to use node-red successfully. Check out the video to see something that node-red allows you to do quickly and easily. At the end of this instructable I also show you what I've done with node-red and the BBB.

One awesome thing about node-red is that there are already nodes that other people have made that you can add to your node-red installation. In our case, the BBB has functions in node-red to read analog and digital channels and write to the various digital channels on the BBB. Check out the picture above to see the current list of BBB nodes.

Photo credit: http://nodered.org/ and http://elinux.org/images/2/23/REV_A5A.jpg

Step 1: Installing Node-Red on Your Beaglebone Black

First, make sure your BBB has an internet connection and SSH in. You'll also want to be on the most recent release of Debian for the BBB to make sure you have the latest version of Node.js (v0.10.x) which should be installed by default on the BBB. Node.js is what node-red is based off of. If you need to update Node.js, follow the instructions on this page under the heading "2014-05-14 GPG error: Optional enable". If you need more detailed instructions, see the node-red documentation.

Also, make sure your local time is correct on the BBB since it does not have a battery backed real time clock. It needs to be set on every boot in order for software certificates date checks to be valid. ntpdate -b -s -u pool.ntp.org should do the trick. I personally did not do this step and had no issues.

To install node-red on your BBB, type the following in the terminal:

sudo npm install -g --unsafe-perm node-red

Let node-red install and you should be almost done!

Next, we want to get the BBB specific nodes so type the following into your terminal:

cd ~/.node-red

npm install node-red-node-beaglebone

Step 2: Starting Node-Red

To start node-red on your BBB, type "node-red-pi" into the terminal without quotes. You'll see some information displayed in the terminal similar to the picture above.

Now, go to http://beaglebone.local:1880 assuming you haven't changed your host name. This URL opens node-red in your browser where you create your "flows". You should notice on the left side of the window there should be a BBB node set if you scroll all the way down that looks like the picture above.

Step 3: Importing Flows

Another great thing about node-red is that it is easy to share your flows with other people. Copy the following code to your clipboard:

[{"id":"184087e6.e7bf78","type":"inject","name":"on","topic":"","payload":"1","repeat":"","once":false,"x":370,"y":188,"z":"345c8adc.cba376","wires":[["919e132f.6e61f"]]},{"id":"25e4d6c.fda1b2a","type":"inject","name":"off","topic":"","payload":"0","repeat":"","once":false,"x":370,"y":228,"z":"345c8adc.cba376","wires":[["919e132f.6e61f"]]},{"id":"6be2c4b9.941d3c","type":"bbb-discrete-out","pin":"USR2","inverting":false,"toggle":false,"defaultState":"0","name":"","x":613,"y":136,"z":"345c8adc.cba376","wires":[[]]},{"id":"919e132f.6e61f","type":"bbb-discrete-out","pin":"USR3","inverting":false,"toggle":false,"defaultState":"0","name":"","x":619,"y":193,"z":"345c8adc.cba376","wires":[[]]},{"id":"1cf2bd40.e30d43","type":"inject","name":"on","topic":"","payload":"1","repeat":"","once":false,"x":368,"y":102,"z":"345c8adc.cba376","wires":[["6be2c4b9.941d3c"]]},{"id":"3e4caa12.c1b356","type":"inject","name":"off","topic":"","payload":"0","repeat":"","once":false,"x":368,"y":142,"z":"345c8adc.cba376","wires":[["6be2c4b9.941d3c"]]}]

Next, click the menu button in the top right corner and go to Import -> Clipboard and paste the code above. Once that is done, you should see the flow pictured above is now in your workspace!

Step 4: Deploy!

Now that we have our flow, we'll need to actually deploy it. Click the deploy button in the top right of your screen and a pop up message will tell you if it was successful. Now, when you click the "on" button or "off" button of the inject node, it will send either a "1" or a "0" respectively to the BBB digital write node that will then turn on user led 2 or user led 3. You can easily use this to toggle other digital channels as well.

If you want to stop node-red, just type ctrl + c into the terminal to quit out of the program.

Step 5: What's Next?

That's up to you! Personally, I used node-red and some html/javascript to create a server on the BBB that allows people to connect to the BBB on the same network it's connected to and toggle a lamp on and off using a relay switch. The page that I made also has toggle switches so you can turn on some of the user LEDs and it also live updates the analog pins 0 and 1 and plots them 20 points at a time using a library called flot. Check out the picture of the page I made above! Sorry for the low resolution it's a screenshot from my phone.

If you're curious to learn more, you can head to the node red website and check out more youtube videos. Feel free to comment any questions you have as well and I'll do my best to answer them!

<p>I did the install (Node-Red v0.14.3, Node.js v0.12.13, Linux 4.4.9, couple hiccups:</p><p>#1 On my Debian 8.5 BBB, the executable was in the /usr/local/node-red folder. The ~/ home did contain a (hidden ls -la) node-red folder, but that only contained the settings.js file. How can the path be updated so that it can be executed from home?</p><p>#2 When I execute .node-red, there is an error about port 1880 already in use, so I changed the settings.js file above to 1881. Doing an lsof -i 1880 shows that systemd pid1 is listening on 1880. What could that be?</p><p>#3 Changing the port, node-red runs fine, but surprisingly, the beagelbone nodes were already listed even though I hadn't run the last install yet (npm install node-red-node-beaglebone). Is it possible node-red comes pre-installed? Is there a command to check what version of node.js / node-red may exist before starting installation?</p><p>#4 Is it possible to copy a node-red design from the local BBB to a cloud node-red server (bluemix, fred, etc)? I imagine any design that uses beaglebone nodes won't work, but if the sketch doesn't use any can it be easily migrated?</p>

About This Instructable

2,455views

13favorites

License:

Bio: Software Engineer at Digilent Inc.
More by Sudharsan Sukumar:Raspberry Pi Rainbow Ruler Getting Started With the Raspberry Pi 2 (LabVIEW) LabVIEW Tutorial: Game Discounts 
Add instructable to: