Random Nerd Tutorials
Shares

Getting Started with Node-RED on Raspberry Pi

Shares

This post is an introductory guide to Node-RED. I’ll cover what’s Node-RED, how to install it, how to use the visual interface to create a simple flow.

Prerequisites

Before you start reading this blog post, I’m making an assumption that you are already familiar with the Raspberry Pi and you know how to install the operating system.

If you don’t, please read this blog post: Getting Started with Raspberry Pi. By the end, you should have Raspbian or Raspbian Lite installed in your Raspberry Pi.

If you like the home automation and you want to learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino. I recommend that you download my course: Build a Home Automation System for $100.

Let’s get started!

What’s Node-RED?

Node-RED is a powerful open source tool for building Internet of Things (IoT) applications with the goal of simplifying the programming component.

It uses a visual programming that allows you to connect code blocks, known as nodes, together to perform a task.

The nodes when wired together are called flows.

node-red-overview

Why do I think Node-RED is a great solution?

Node-RED is open source and developed by IBM.

The Raspberry Pi runs Node-RED perfectly.

With Node-RED you can spend more time making cool stuff, rather than spending countless hours writing code.

Don’t get me wrong. I love programming and there is code that needs to be written throughout this course, but Node-RED allows you to prototype a complex home automation system quickly.

What can you do with Node-RED?

Node-RED makes it easy to:

  • Access your RPi GPIOs
  • Establish an MQTT connection with other boards (Arduino, ESP8266, etc)
  • Create a responsive graphical user interface for your projects
  • Communicate with third-party services (IFTTT.com, Adafruit.io, Thing Speak, etc)
  • Retrieve data from the web (weather forecast, stock prices, emails. etc)
  • Create time triggered events
  • Store and retrieve data from a database

Here’s a library with some examples of flows and nodes for Node-RED.

Installing Node-RED

Getting Node-RED installed in your Raspberry Pi is quick and easy. It just takes a few commands.

Having an SSH connection established with your Raspberry Pi, enter the following commands to install Node-RED:

pi@raspberry:~ $ bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

The installation should be completed after a couple of minutes.

Autostart Node-RED on boot

To automatically run Node-RED when the Pi boots up, you need to enter the following command:

pi@raspberry:~ $ sudo systemctl enable nodered.service

Now, restart your Pi so the autostart takes effect:

pi@raspberry:~ $ sudo reboot

Testing the Installation

When your Pi is back on, you can test the installation by entering the IP address of your Pi in a web browser followed by the 1880 port number:

http://YOUR_RPi_IP_ADDRESS:1880

In my case is:

http://192.168.1.98:1880

A page like this loads:

node-red-first-look

Node-RED overview

Let’s take a look at the Node-RED visual interface.

node-red-raspberrypi

Main sections

On the left-side, you can see a list with a bunch of blocks. These blocks are called nodes and they are separated by their functionality. If you select a node, you can see how it works in the info tab.

In the center, you have the Flow and this is where you place the nodes.

node-red-raspberrypi-sections

Creating a simple flow

Let’s test a simple example of a flow. Start by dragging an Inject node to your flow. Then, also drag a Debug node.

simple-floww

Connect your nodes together. You can drag them to confirm that they are connected.

Now, let’s edit the inject node. Double-click the node. In the figure below you can see different settings you can change.

Select string and type Hello!.

edit-inject-node

To save your application, you need to click the deploy button on the top right corner.

deploy-button

Your application is saved.

Testing the flow

Let’s test our simple flow. Open the debug window and click theInject node to trigger the “Hello!” string.

node-red-f

As you can see, our message is being printed in the debug window. This is a very basic example and it doesn’t do anything useful. However, the purpose of this post is to get you familiar with the Node-RED interface.

Wrapping Up

This post is a quick guide to setup Node-RED on a Raspberry Pi and create a simple flow. I’ll be posting future tutorials doing things with a real world application, but I thought it would be useful to introduce this software first.

Like home automation? Learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino with my course: Build a Home Automation System for $100.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off