Description

Node-RED is a programming tool for wiring together hardware devices, APIs and online services  in new and interesting ways. It provides a brower-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.This article will explain how to execute shell commands in node-red. 


Requirement

Any Milesight device with node-red embedded can be used. Here, we will use the UG65 gateway as an example.


Configuration

1. Create a flow canvas, then drag and drop three nodes: an inject node, an exec node, and a debug node. Connect them together as shown in the image. 


2. configure the parameters for each node separately: 

inject node: This plugin marks the starting point of the flow. In this demonstration, the flow is triggered 3 seconds after the node-red system starts. The relevant configuration is shown in the image:


exec node: This plugin is the key for executing shell commands. The content inside should be the specific shell command you need to execute and should be filled out according to your actual requirements. 

The command to be executed here is: 

source /etc/profile && /usr/sbin/iptables -I INPUT -p tcp --dport 10889 -j ACCEPT


debug node: This is used solely for debugging purposes to view the debug logs.



3. Debug and Run

After configuring all the nodes, you can manually trigger the inject node to start the entire flow by clicking the button in front of the inject node, as shown in the picture. 


Click once, and you will see a popup window as shown in the picture and the output of debug logs on the right. If there is no error message, it means your command has been executed successfully. Next, you can proceed with verification according to your actual needs. For example, in the case of enabling or disabling ports, you can use ping tools for testing. Further details will not be elaborated here.