Node RED OpenWRT Overview - cu-ecen-aeld/buildroot-assignments-base GitHub Wiki
Node-RED is a visual programming tool that allows users to create applications by connecting "nodes" together. It is often used for Internet of Things (IoT) applications but can be used for a wide variety of purposes. It is built on top of Node.js, a JavaScript runtime environment, and uses a flow-based programming model, which means that applications are created by connecting together small units of functionality, or "nodes," in a visual manner.
Node-RED installation
First we installed Git, Node.js and npm on the OpenWRT Router with the opkg package manager
Node-RED installation via NPM was not successful with the following command due to dependency issues.
npm install node-red
Hence the source code for Node-RED was cloned from (https://github.com/node-red/node-red) and the following commands were used to install and build the code.
- npm install (install packages)
- npm run build (build root)
- npm start (start the node-red sever)
With the above process, we were able to run Node-RED at localhost:1880 on the OpenWRT Raspberry Pi.
Starting Node-RED on Bootup
This process can vary based on the init system, on OpenWRT you can follow the following steps.
- Create a script called 'S99StartNodeRed' and put the following lines in the script.
#!/bin/sh
/path/to/node-red/folder
npm start
- Give the execution permission by running the following command.
chmod +x S99StartNodeRed
Alternatively, you can also copy the Node-RED binary which is built to the /usr/bin directory and execute it from an init script.
Setting up Node-RED to communicate over TCP
The nodes to communicate over TCP are available by default and can be used to listen or connect to a TCP socket on a specific port of a host on the network. There are specific nodes to receive or send data. When data is fed into the input of a TCP out node, the data is sent over TCP to the connected.
Additional nodes can be installed via the 'Manage Palette' sub-menu. In the below image, the 'node-red-dashboard' (installed via palette) is a collection of nodes with which a functional dashboard can be created.
Note: Internet Access is needed on the OpenWRT Router to install new nodes into Node-RED.
Using Node-RED on OpenWRT to Manage Applications on the Network
Node-RED on OpenWRT can be used to set up a Management Server to send commands to the Applications running on the network. The Applications on the network will need to implement a socket to connect to the management server.
It is preferred to run the management socket on a thread separate from the application code. An implementation for a project is explained below with links to relevant pieces of code.
Management Interface with TCP Socket
- In this setup, there is a UI with control elements to manage the demo and features. This control/management data is sent over to the client and server over TCP sockets. The client and server implement a secondary management socket on a different thread to receive these messages and act on the main thread which is running the demo. The above diagram shows the implementation.
- The code to set up a management socket and parse simple commands can be found here in the main function.
The specific Node-RED config file and instructions to use it can be found in the issue tracker below. The config file is a JSON structure describing different nodes present and their configurations too.
The issue tracker also contains screen captures of the Management User Interface.
The issue tracker -> issue