table of Contents
table of Contents
Four, HelloWorld sample program
1. Introduction to Node-RED
Node-RED is a visual programming tool developed by IBM to meet their needs for quickly connecting hardware and devices to Web services and other software, and it quickly developed into a universal programming tool for the Internet of Things . Node-RED is a programming tool based on "Flows". It has a visual editor that allows pre-defined code blocks (called "nodes", Node) to be connected to perform tasks. The connected nodes are usually a combination of input nodes, processing nodes and output nodes. When they are connected together, they form a "flow" (Flows).
Two, Node-RED installation
1. Regular installation
1) Node.js installation
Node-RED is a visual flow programming tool developed based on Node.js. To install Node-RED, you first need to install Node.js
Download the LTS (Long Term Support) version on the Node.js official website https://nodejs.org/en/ .
Npm is a package management tool, but because its server is slow to access abroad. You can use Taobao mirror cnpm to replace the official version to speed up access. The synchronization frequency is once every 10 minutes to ensure that it is synchronized with the official service as much as possible.
Enter in CMD npm install -g cnpm --registry=https://registry.npm.taobao.org
to install
3) Node-RED installation
Enter in CMD cnpm install -g node-red
to install 2. Regular installation
2. Docker installation
docker pull nodered/node-red-docker
docker run -it -p 1880:1880 nodered/node-red
Three, basic operation
1. Start
Enter in CMD to node-red
start the Node-RED daemon,
Open http://localhost:1880 in the browser to access the front-end interface of Node-RED for programming.
2. Programming and deployment
Open the Node-RED interface, you can see that it is mainly composed of three working areas, the node board (left), the flow programming interface (middle), and the output debugging pane (right).
The flow programming workspace is located in the middle of the interface, where you can drag and drop the nodes in the left pane to the corresponding positions, and connect them by lines. Double-click the node to open the editing interface to perform specific programming operations on the nodes. At the top of the pane is a set of tabs, you can easily switch or add a new process, double-click to open the editing interface to add a description, rename or delete the current process.
The node board is located on the left side of the interface. It contains all the nodes supported by the built-in Node-RED instances, as well as custom-developed nodes, which will be described in detail in the next section.
On the right is the output debugging pane . After the program is edited, click the red button on the upper right to deploy. The debugging pane will display debugging output information, errors and warnings.
3. Node commonly used nodes
1) Basic node type
(1) Input node
Input node ( for example, inject) , there will be an output endpoint on the right, which can input data into the current Node-RED flow.
(2) Output node
For output nodes (such as debug) , there will be input endpoints on the left, allowing data to be output outside the Node-RED stream.
(3) Function node
Function nodes (such as function) are used to perform specific functions, and generally include at least one input node and one output node.
In addition to the above three basic nodes, Node-RED also includes nodes such as network, sequence, analysis, and storage.
2) Node query
Click the help on the right, enter the name of the node you want to query in the search bar, you can see the detailed node information provided by the official
3) Import of nodes
Click the menu button in the upper right corner, select -> Node Management
Pop-up user settings window, which can realize the search, installation, enable and disable of nodes
4. Process import and export
1) Export of process
Click the menu button in the upper right corner, select -> Import, you can choose to export the process to the clipboard or library.
(1) Export to clipboard
(2) Export to library
2) Import of process
Process import also includes three methods: import from clipboard, import from library, import from example
Four, HelloWorld sample program
(1) Start Node-RED and open the programming interface in the browser
(2) Drag an inject node from the left to the flow programming area
(3) Double-click to modify the properties of the inject node, change the type of msg.payload to a text column, add the content "Hello world", and check the "Execute now"
(4) Drag and drop a debug node from the left to the flow programming area, and connect it with a line
(5) Click the "Deploy" button on the upper right, and you can see the output of "Hello world" in the debug window on the right