Node-RED, an open-source tool based on streaming programming, provides developers with a flexible visual programming approach, enabling IOTRouter’s EG Edge Computing Gateway to easily connect to a variety of data sources for data processing and conversion. The EG Edge Computing Gateway is able to collect and initially analyze data in real-time at the edge where the data is being generated, which reduces bandwidth requirements and improves data processing efficiency. It can also collect data through various protocols (e.g., Modbus, MQTT, OPC UA, etc.) and perform the necessary conversion and storage of data.
I. Basic Functions of EG Edge Computing Gateway
EG Edge Computing Gateway plays the role of the middle layer of data collection and processing in the system, and flexibly processes data from multiple sensors and devices for real-time filtering and preliminary analysis. EG Edge Computing Gateway has the following functions:
Protocol conversion: Support data transmission protocols between different devices, such as Modbus, OPC UA, MQTT, etc.
Local processing and analysis: Provides computing power to filter, convert and simply analyze data.
Data Storage and Transmission: Transmits processed data over the network to a database in the cloud or local server.
II. Working Mechanism of Node-RED
Node-RED provides a browser-based flow editor that allows users to drag and drop nodes to create data processing flows. Each node has input and output characteristics and is capable of performing specific data processing tasks. Node-RED has rich plug-in support, such as Modbus, MQTT, OPC UA, etc., which makes it capable of integrating multiple data sources.
III. Data Acquisition and Processing
Reference process: collect data from slave devices regularly through EG gateway, and format the collected data into a format recognizable by MySQL database, and upload the user’s own MySQL database. Here take the collection of Modbus RTU slave data upload as an example, the operation flow is as follows:
1. Connect to MySQL database
First make sure to install MySQL node, then in Node-RED editor, add MySQL node and configure database connection parameters, including host, port, username, password and database name.
Use the MySQL node to configure the user’s MySQL database connection parameters, the configuration is completed and deployed, and the display connected means the connection is successful.
2. Collect slave data
Use Modbus RTU data acquisition
Configure the host address and port of the Modbus node and specify the data registers to be collected.
Create a data collection process to connect the Modbus node to the MySQL node. Set up a timer node to periodically trigger the data collection task to ensure real-time and accurate data.
3. Data Formatting
When data is uploaded to the MySQL database, it needs to be formatted into the correct SQL statement according to MySQL requirements. Use the function calculation node to format the data. The data format to be converted is as follows:
Modbus node output data format | Description | MySQL SQL format for uploading data |
{
“temp”: 31.0, “hum”: 45.5 } |
Converts the object data output from the Modbus node on the left to the SQL statement required by MySQL on the right. | INSERT INTO my_table (temp, hum) VALUES (25.55, 45.5); |
Sample Code:
var data = msg.payload var sql = `INSERT INTO my_table (temp, hum) VALUES(${data.temp},${data.hum});` msg.topic = sql return msg;
4. Data Upload
After the data formatting is completed, connect the function calculation node and MySQL node, and click the injection node to realize data collection and uploading. Successful testing can set the injection node to execute periodically to realize data collection and uploading to MySQL database at regular intervals.
The EG edge computing gateway collects data at regular intervals and converts them into MySQL-supported formats, a method that realizes real-time processing and long-term storage of large amounts of field device data. It improves data processing efficiency and can provide a basis for subsequent data analysis and decision-making. The introduction of edge computing allows the initial processing of data to be completed close to the data source, reducing the dependence on cloud computing and lowering the latency and cost of data transmission.
Note: If you need to get data from the MySQL database, you can also upload a MySQL node by passing a reference SQL statement to the msg.topic property to make a request for data.