One tool that continues to make IoT and industrial solutions easier is Node-RED. Designed and built by IBM, Node-RED is an free, open source logic engine that allows to programmers of any level to interconnect physical I/O, cloud-based systems, databases, and API’s. User interact with Node-RED via a browser-based flow editor that makes multi-device and multi-API integrations as easy as linking together nodes into easily understood flows.
To learn how you can better leverage the flexibility and visualization of projects with Node-RED continue reading.
In this article we will install and run Node-RED in a Raspberry Pi to quickly and easily develop and deploy your next IoT solution.
IMPORTANT NOTE: This guide assumes your Raspberry Pi has been configured and is already connected to the Internet. If not yet configured, you can quickly do so using this quick start guide from the Raspberry Pi Foundation.
- Raspberry Pi already configured and connected to internet
Setting up NodeRed
1. To start the installation, access the Raspberry Pi via your prefered method. This can be done using the Desktop Interface (connecting a monitor, keyboard, and mouse to the Raspberry Pi), or simply by accessing the Pi Remotely using your computer’s terminal as a secure shell, or SSH.
With your Raspberry Pi connected to the internet, follow the steps below based in the method chosen to access to the Raspberry Pi:
- Desktop Interface: Open the terminal from Menu -> Accessories -> Terminal
- Remotely (SSH): Verify the IP address assigned to the board and access to it using ssh in your computer's terminal:
The default credentials to access to the Raspberry are:
- User Name: pi
- Password: raspberry
As you can see the image below, once you have access to the Pi, your username will update from the user’s PC, in this case:
2. Once you have access to the Raspberry Pi, update the list of available packages and their versions to start your solution with everything up-to-date.
sudo apt-get update
3. Install the latest version of packages - previously updated (step 2)
sudo apt-get upgrade
This will take a couple of minutes! Relax, and be patient (we recommend coffee) and when you return the updates will be complete. 👻
1. Node-RED comes pre-installed on the full Raspbian SD image card. While usable, this uses an older version of Node.js. We recommend upgrading to the latest version by running the below command in the Pi’s terminal:
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
Here you can reference the official documentation for a detailed explanation of this update command.
2. Once your image card has been updated, confirm the installation by inserting
Y when asked for verification.
Once the installation is finished, you will receive the following verification:
Following the steps below we will configure the Raspberry Pi.
1. To start Node-RED:
- From the Pi’s Desktop Interface: Select Menu -> Programming -> Node-RED
- Remotely from your Computer’s Terminal: Run node-red-start in a new Raspberry Pi terminal window.
1.1. Once the command is inserted wait a couple seconds until the Node-RED server starts running. As you can see on the image below the terminal logs lets you know the device IP and port where that the Node-RED server will be pointing.
The service is pointing to port 1880:
1.2. Once the Node-RED program has started, open a web-browser of your preference and in the URL navigation bar write the address shown in the first main line of your Node-RED terminal as captured below.
1.3. In my case, I access to the Node-RED web interface using http://192.168.0.20:1880. When you run the URL address in your browser you should be able to visualize the Noded-RED interface as shown below:
Common Commands when using Node-RED with Raspberry Pis
2. To see the log, run the command:
3. If you want Node-RED to run when the Pi boots up you can use:
sudo systemctl enable nodered.service
4. To stop Node-RED, run the command. Note: closing the window (or ctrl-c) does not stop Node-RED running. The program will continue running in the background unless you execute a -stop command.
With Node-RED installed and configured in the Raspberry Pi, this Pi is now ready to handle different development flows. If you really want to make your solutions valuable to end-users, link your Node-RED data to the internet and use an IoT Application Enablement platform to enhance the raw data into insights as data driven applications that improve your business or operations. To learn how to send data to IoT App Enablement and Development platforms like Ubidots, check out this simple guide to quickly setup the data-communication highway form the Pi to the Cloud.
Need more functionality? In the Node-RED documentation you can find new nodes available, share your flows, and see what other flows have been built with Node-RED.