How Node-Red communicates with OPC DA server

1. Introduction

This article mainly introduces how Node-Red uses the plug-in node-red-contrib-opc-da and the plug-in node-red-contrib-opcda-client to communicate with the OPC DA server, and uses KEPServer to simulate the server.

  • Environment setup

This environment setup requires two machines, in the same LAN:

Server

Function: Simulate OPC DA server

Operating system: Windows 7 Professional

Client computer

Function: Used for OPC DA client remote connection test

Operating system: Windows 11 Home Chinese version

Install KEPServer

First, install KEPServer on the server machine that requires the server. If an installation error occurs, the following dialog box pops up:

The installer was unable to find required root certificates. Please apply Windows updates. If unable to apply Windows Updates,contact support for instructions on installing root certificates.

It prompts that a root certificate is required. Now let’s install the root certificate. Open the command line and enter “mmc”. The following interface will pop up.

Click the File->Add/Remove Snap-in (M)… menu, and the following dialog box will pop up.

Select “Certificate” from the list on the left side of the dialog box, click the Add button in the middle, and select the “Computer Account” option in the pop-up window.

Click “Next” and select the “Local Computer” option,

Then click the “Finish” button to confirm.

Return to the Add or Remove Snap-in dialog box and click the “OK” button to complete the addition.

Locate the “Console Root Node->Certificate (Local Computer)->Trusted Root Certification Authority->Certificate” node in the tree list on the left, right-click on the node and select “All Tasks->Import “menu, the pop-up dialog box is as follows,

Click the “Next” button,

Click the “Browse” button to open the file selection dialog box, select the first certificate “Globalsign Root CA – R3”, and click the “Open” button to confirm.

Return to the “Certificate Import Interface” and click the “Next” button

Select the “Place all certificates into the following certificate store” option and click the “Next” button.

Finally click the “Finish” button to complete the certificate import, and then import the second certificate “MicRooCerAut2011_2011_03_22” in the same way.

Reinstall KEPServer,

Initialization was successful and no previous error dialog box popped up.

Select the “Skip setting a password at this time” option here, keep the rest as default, and the installation is completed successfully.

Starting KEPServer will automatically start the OPC DA server without additional configuration.

Add account

The Node-Red plug-in needs to connect to the OPC DA server through an account, so you need to create a new account and grant the corresponding permissions. Right-click the “My Computer” icon on the desktop, select the “Management” menu, and click on the left side of the pop-up dialog box. Navigate to the “Computer Management->System Tools->Local Users and Groups->Users” node in the side list.

Right-click the mouse on the node and select the “New User” menu to pop up the user creation dialog box.

Enter “opcda” as the user name, set the password to “123456”, check the “Password never expires” option, click the Create button to complete the new user, close the “New User” dialog box, and you can see the newly created user.

Right-click on the new user “opcda”, select the “Properties” menu, and select the “Belongs to” label in the pop-up dialog box

Click the “Add” button and the dialog box will pop up as follows:

Then click the “Advanced” button, and then click the “Find Now” button, as shown below

Select the “Distributed COM Users” option in the “Search Results” list and click the “OK” button.

Return to the “Select Group” dialog box and click the “OK” button again to complete the settings.

DCOM Settings

Open the control panel, as shown below

Switch the view mode to “Large icons”

Click “Administrative Tools”, double-click the “Component Services” shortcut in the pop-up window, open the “Component Services” window, and locate the “Console Root Node->Computer->My Computer” node

Right-click the mouse on the node, select the “Properties” menu item, and select the “COM Security” tab in the pop-up dialog box

Click the “Launch and Activation Permissions->Edit Restrictions” button to open the “Launch and Activation Permissions” dialog box

Click the “Add” button to open the “Select User or Group” dialog box

Click the “Advanced” button and click the “Find Now” button in the pop-up dialog box

Select the “Distributed COM Users” user group, which is the group to which the new user “opcda” has joined. After the selection is completed, return to the “Startup and Activation Permissions” dialog box and select “Local Start” and “Remote Start” corresponding to the user group. ”, “Local Activation”, and “Remote Activation” and then check “Allow” and confirm.

Click the “Launch and Activation Permissions->Edit Defaults” button to grant the corresponding permissions in the same way.

Locate the “Console Root Node->Computer->My Computer->DCOM Configuration” node in the tree list on the left side of the “Component Services” window, and then press the “k” key on the keyboard to quickly search for ” KEPServerEX 6.5” node,

Right-click the node and select the “Properties” menu item.

Record the “Application ID” value “7BCOCC8E-482C-47CA-ABDC-OFE7F9C6E729”, which will be used when connecting later. Restart the machine after the setting is completed.

3. Node-Red settings

Local testing
Server Node.js installation

The local test environment is relatively simple. First check whether the local test can pass. Since the operating system of the server machine is Windows 7, higher versions of Node.js are not supported, so there are requirements for the version of Node.js. Here you can only choose the highest possible version. version, I have tried many versions and gone through many pitfalls, and I am sure that v14.15.1 can run normally. After the installation is completed, the following prompt will appear when you use the command to display the version:

Follow the prompts to add the environment variable NODE_SKIP_PLATFORM_CHECK and set its value to “1”

Display version number correctly

Node-Red Installation

Run “cmd.exe” as an administrator and enter the command to switch Node.js to the Taobao image, so the installation will be faster:

npm config set registry https://registry.npm.taobao.org

Enter the command to install Node-Red:

npm install -g --unsafe-perm node-red

After a while, the installation was successful.

Start Node-Red, and install the plug-in node-red-contrib-opc-da and the plug-in node-red-contrib-opcda-client respectively on the workbench.

Plug-innode-red-contrib-opcda-client Settings

In the left panel of Node-Red, drag an inject node, an opcda-read node and a debug node to the workspace, and link the three nodes in sequence.

Double-click the opc-read node to open the settings dialog box

Click the “pen” button on the far right of Server to add the OPC DA server. The Address is “localhost” and the Domain is empty, but it must be filled in. It is represented by two quotation marks. The User Name is the newly created system account “opcda” and the Password The account password is “123456”, and the ClsId is the application ID recorded earlier “7BCOCC8E-482C-47CA-ABDC-OFE7F9C6E729”. Then click the Browse button to test and read 373 pieces of data, indicating that the connection is successful.

Copy the two data “Data type example.16-bit device.K register.Double1” and “Data type example.16-bit device.K register.Float1″ from the read variable list. Click the Add button to confirm and return to ” Edit opcda-read node” interface,

Add the two data copied above to the Items list, click the Finish button to confirm, and deploy the process.

Click the inject (timestamp) node to trigger the flow. The debugging window displays as follows:

The data from the server can be read correctly.

Next, let’s see how to write data to the OPC DA server. Copy the three nodes in the current workbench, replace the opcda-reada node with the opcda-write node, and insert a function node in front of the opcda-write node.

Double-click the function1 node to bring up the editing dialog box and enter the following code:

msg.payload = [
    {"itemID": "Data type example.16-bit device.K register.Float1", "type": "float", "value": 88},
    {"itemID": "Data type example.16-bit device.K register.Double1", "type": "double", "value": 888}
    ];
return msg;

The code indicates that the values 88 and 888 are written to the two variables respectively. Click the Finish button to confirm, double-click the opcda-write node, select “opcda-server” from the drop-down box, and confirm the editing and deployment process.

Click the inject (timestamp) node of the stream to trigger the stream. The debug window displays the return value as “true”, indicating that the writing is correct.

Click the inject (timestamp) node in front of the opcda-read node again to read the data to verify the writing result. The debugging window displays as follows:

The written value is correct.

Pluginnode-red-contrib-opc-daSettings

Drag an opc-da in node and a debug node from the left panel of Node-Red to the workspace and connect the two nodes

Double-click the opc-da in node to open the editing dialog box

Click the “pen” button on the far right of the OPC Group entry to open the Add Group dialog box

Click the “pen-shaped” button on the far right of the OPC Group entry again to open the Add OPC DA Server dialog box. Fill in the server information. The parameters are the same as above. Then click the Test and get items button to test. The information read will be displayed in Server items. Variable, click the “Add” button to confirm.

Return to the Add Group dialog box, fill in the group name “group1″ in the Name field, select the variable to be read in the Items drop-down box, and add it to the list below. For the convenience of testing, select the same two variables above. Data type example.16-bit device.K register.Double1” and “Data type example.16-bit device.K register.Float1”, click the “Add” button to confirm.

Return to the opc-da in node editing dialog box, select the “All items” option in Mode, and click the “Finish” button to confirm.

During the deployment process, the stream will loop to read the added variables. The debugging window displays as follows:

The local test is successful. Now export the process. Click the “Main Menu (three horizontal lines) -> Export” menu item in the upper right corner of the Node-Red workbench to open the export dialog box.

Select the “All Processes” option, select “JSON” for the label below, and click the “Download” button to export the process.

Remote testing
Server firewall settings

Open the “Control Panel->System and Security->Windows Firewall” interface on the server machine.

Click “Advanced Settings” on the left to open the “Windows Firewall with Advanced Security” dialog box, and locate the “Inbound Rules” node in the tree list on the left

Then click the “Action->New Rule” menu to open the “New Inbound Rule Wizard”

“Program” is selected by default, leave it unchanged, and click “Next”

Click the “Browse” button behind “This program path”, locate the installation path of KEPServer, and select “server_runtime”

After confirmation, click “Next”

Leave it unchanged and go to “Next”

Select “Domain”, “Private” and “Public” at the same time, then “Next”

Name it “kepserver_server_runtime” and click “Finish” to end adding inbound rules.

Client Node.js installation

The Node.js version initially installed on the client was v20.9.0. When testing with the opcda plug-in, the following error kept appearing:

Error: Exception occurred while forming Session Security Type3Response

I searched for some information and found that it seems to be related to the version of openssl.

So downgrade the Node.js version to v14.15.1. The version is consistent with the one on the server machine. The problem is solved. Other v14 versions should also work. Please test it yourself.

Node-Red process import

Install Node.js and Node-Red, start the program, import the process exported from the server earlier, click the “Main Menu (three horizontal lines) -> Import” menu item in the upper right corner of the Node-Red workbench to open the import dialog box

Select the file to be imported and click the “Import” button to import the process.

Double-click the opcda-read node, and in the opened “Edit opcda-read node” dialog box, click the “pen-shaped” button on the right side of the Server entry to open the Server editing dialog box.

Enter the IP address of the server machine in the Address field, here it is “192.168.80.141”, the User Name is the newly created account “opcda” for the service, and the Password is the password of the new account “123456”. The rest remains unchanged. After confirming the modification, return Workbench. Then modify the OPC DA server parameters of the opc-da in node (named group1 on the workbench) to the same value, and confirm the modified deployment process. Note, if the connection is unstable after deployment, please restart Node-Red.

The debugging window shows that communication is normal:

If you want to get the code, tools and other information related to the article, follow the public account “NodeRed Internet of Things” and reply “nr”.