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.
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:
[email protected]:~ $ 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:
[email protected]:~ $ sudo systemctl enable nodered.service
Now, restart your Pi so the autostart takes effect:
[email protected]:~ $ 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 overview
Let’s take a look at the Node-RED visual interface.
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.
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.
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!.
To save your application, you need to click the deploy button on the top right corner.
Your application is saved.
Testing the flow
Let’s test our simple flow. Open the debug window and click the Inject node to trigger the “Hello!” string.
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.
Thanks. I will try it out.
Well written article.
You’re welcome. thanks for reading,
Rui
Looks great! I’ll try this!
Thanks for sharing!
You’re welcome,
Thanks for reading,
Rui
sudo apt-get install nodered
Reading package lists… Done
Building dependency tree
Building state information… Done
E: Unable to locate package nodered
Looks like you’re not using Raspbian OS or something, because it’s missing the nodered package that should come by default.
Thanks,
Rui
Thanks a lot! I’ve been looking for something more refine then scratch to introduce my high school students to Raspberry Pie programming, I think I may have found it!
Thanks! I’m glad you found it useful,
Rui
To install node-red it is recomended to use: sudo npm install -g node-red
Thanks Viktors!
Thanks for the great video. I am presently using Adafruit.io as a broker and ESP8266 as devices.
This arrangement works well for me. My concern is that I depend on Adafruit as a broker. My question is: does your system give me independence by running on Raspberry Pi? Can I connect to it from anywhere in the world? is it limited to “Home Automation” or can it be autonomous ?
Jacob
With the system that I should you install the MQTT broker (mosquitto broker) locally in your Raspberry Pi and you install a software called ngrok that allows you access your device securely from anywhere in the world.
You could always change your MQTT broker from Adafruit to another service quite easily.
Thanks for asking,
Rui
I want to thank you on the great tutorials of raspberry-Pi and mosquito installation. I like your format of line by line instructions rather than lengthy Youtube videos.
My question is: I prefer to use the mosquito as a broker rather than Adafruit.io and be independent, so now, do I need the both Node-RED and the Python server for MQTT?
I have mosquito installed and tested, now I am not sure if I should just continue with Node-RED or what? I am not too interested in Home Automation very much but I want to access my mosquito from anywhere on the web. Will I be able to do it with Node-RED?
Thank you very much,
Jacob
Do you use anything else besides mosquitto and node-red(Home Assistant or OpenHAB)?
Hi Leonardo.
Our MQTT tutorials use Raspberry Pi, Node-RED, and Mosquitto.
We don’t have tutorials with OpenHAB or Home Assistant.
Regards,
Sara 🙂
loaded a freshly made SD card and after it finished installing, I looked under the programming flyout and there is no node-red. I had to load it with the link you provided.