Downloading Node-RED Flow to Raspberry Pi from GitHub

Kazuhito Yokoi
7 min readMay 28, 2023

--

Node-RED supports different environments for running flows because it runs on Node.js, which can be installed on Windows, macOS, Ubuntu, and other Linux-based operating systems. In the Industrial IoT market, many edge devices supporting Linux and Node-RED have been released by major hardware vendors (product list on the FlowForge blog).
In general, flow developers tend to use pre-installed Node-RED without Git integration by default to develop flows on these devices. However, some edge devices may not be suitable for the development environment because these devices are optimized for low power and high availability on-premises. Due to limited computing resources, you might encounter performance issues such as slow behavior of the flow editor in the browser, or long processing time after clicking the Deploy button.
Enabling the Git integration on the edge devices will dramatically improve overall development efficiency by separating the development environment and production environment on the edge device. As you can see in the diagram below, flow developers develop the flow on their local PC, such as Windows or Mac, and then, upload it to the GitHub repository. After the flow is imported to the edge devices via the GitHub repository, the Node-RED environment on the edge device executes the flow as ever.

Recently, local computers have been equipped with powerful CPUs such as Apple ARM processors. Therefore, flow developers can quickly develop the flow in the local environment without performance issues. The Git integration eliminates the need to develop the flow on the edge device, as Node-RED simply downloads the flow from the Git repository and executes it.
In this tutorial, I used the Raspberry Pi 4 because it is a well-known edge device suitable for the Node-RED environment. As an example of Node-RED flow, I used the image recognition flow, which recognizes the object name from a web camera using TensorFlow technology. I have already uploaded this flow, along with configuration files such as package.json and README.md files, to the following repository (if you are interested in how to create and upload the flow to the GitHub repository, see the previous article).

GitHub repository: https://github.com/kazuhitoyokoi/tensorflowjs-app.git

Let’s apply the flow to the Node-RED environment on the Raspberry Pi.

Preparing the Devices

I used the following devices for this tutorial.

  • Raspberry Pi 4 Model B (4GB RAM)
  • USB camera (Elecom UCAM-C310FBBK)
  • 32GB micro SD card
  • AC adapter to USB-C

To use the Raspberry Pi as a standalone, you will also need a display, an HDMI cable (micro-HDMI to HDMI), a USB keyboard, and a USB mouse are required. In the following photo, all the parts are connected to the Raspberry Pi.

To test the image recognition application, I used the pet bottle. This application can classify 90 objects defined in the code, including the bottle.
Raspberry Pi OS is used as the operating system for the Raspberry Pi. The Raspberry Pi Imager, which can be downloaded from the following official website, is helpful in writing the OS to the SD card.

Raspberry Pi Imager: https://www.raspberrypi.com/software/

After installing this writing tool on your computer, select the “Raspberry Pi OS (32-bit)”.

This OS image includes the desktop user interface, the Chromium browser, and the git command which is needed for the git integration. After booting the Raspberry Pi using the SD card, you will see the desktop interface on your screen.

Installing Node-RED

The latest Raspberry Pi OS does not include Node-RED by default. Therefore, you need to install Node-RED using the installation script explained on the official website.

Running on Raspberry Pi: https://nodered.org/docs/getting-started/raspberrypi

To run the script, open the Terminal on the Raspberry Pi OS’s desktop, and then paste the following command.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

This command requires an internet connection as it downloads the script and additional components. Wi-Fi connections or a wired network should be configured before running the command.
This script displays a command line wizard for installing and customizing Node-RED. After installing Node-RED, the wizard asks “Would you like to customise the settings now (y/N) ?”. Type “y” to customize the settings of the Node-RED environment.

As you can see in the screenshot above, select “Yes” to the “Do you want to enable the Projects feature?”. When the script is finished, type the “node-red” command to start Node-RED.

Downloading the Node-RED flow

Next, let’s import the Node-RED flow from the GitHub repository into the Node-RED environment on the Raspberry Pi. After opening “http://localhost:1880" in the Chromium browser on the desktop user interface of the Raspberry Pi OS, the following project wizard will pop up.

In the project wizard, click the “Open existing project” text at the bottom. After configuring the user settings for the git client, the following dialog will appear with the three options.

Select the “Clone Project”, and paste the GitHub repository URL, “https://github.com/kazuhitoyokoi/tensorflowjs-app.git" into the “Git repository URL” text input. At this time, the repository type was set to public. Therefore, a username and password are not required to access the GitHub repository (if the repository is private, you must enter your GitHub username and token as the password). In the last step of the wizard, click the “Clone Project” button to download the flow and configurations from the GitHub repository.
As soon as the flow is loaded, the flow editor will notify the warning dialog with the message, “Flows stopped due to missing node types.” because the flow editor has not yet installed the additional nodes. For this reason, the flow also consists of the unknown nodes. To resolve this situation, you need to install the additional nodes from the project settings based on the dependencies information defined in the package.json file. To open the Project Settings interface, click the ellipsis button next to the project name on the Information tab.

In the Dependencies tab of the Project Settings UI, there are required nodes with npm module names and version numbers. To install these additional nodes in the Node-RED environment, click the “Install” button for each node.

After installing the additional nodes, the unknown nodes will disappear from the flow as shown in the screenshot. And then, this flow will be executed immediately. Let’s check the behavior of the image recognition application. Click the arrowed box icon in the Dashboard tab to open the Node-RED dashboard, which displays the image recognition application UI.

The application UI consists of the camera UI and the text area for displaying the object name detected by the image recognition engine.

After placing the pet bottle in front of the USB camera, click the camera icon in the lower right corner of the camera UI. If the recognition process is successful, the annotated image with the orange transparent rectangle and the object name will be displayed in the UI components.

Conclusion

In this article, I have shown how to apply the Node-RED flow from the GitHub repository to Raspberry Pi. This flow deployment style has several advantages over the flow editor without Git integration.
In normal operation, flow developers tend to install additional nodes in the Palette tab of the User Settings UI. But this operation sometimes has serious problems because this UI always installs the latest version of the nodes. If the node specifications are changed dramatically by a node developer after the flow is developed, the flow will have errors due to version mismatch between the flow and the nodes used. In the method presented in this tutorial, the flow can avoid this situation because the required node version is defined in the package.json file provided with the flow files on the GitHub repository.
In addition, compared to importing the flow using the Import nodes dialog, it also makes it easier to update the flow on the device when some changes are added to the Git repository. The traditional way requires users to delete the previous flow with configuration nodes and subflows carefully and import the new flow from the flow file.
When there are multiple devices in the field, such as on the shop floor, applying the flow is a time-consuming task. Using the Git integration, applying the flow to them with a few clicks is another advantage of this method.
This method will be the default for deploying the flow to the devices.

--

--

No responses yet