calling OPC UA methods
You can call OPC UA methods using the OPC UA Call Node
.
OPC UA methods are server-side functions that can perform operations, execute commands, or return calculated values. The Call Node allows you to invoke these methods with input parameters and receive output results.
Methods are essential for controlling devices, triggering operations, and executing server-side logic in industrial automation systems.
prerequisites
- Node-RED installed and running
- @opcua/for-node-red package installed
- Access to an OPC UA server with callable methods
- A configured OPC UA endpoint connection
- Understanding of OPC UA object model and method concepts
See Create a connection to OPC UA server for connection setup details.
step-by-step tutorial
step 1: add the Call node to your flow
- Open Node-RED Editor in your browser
- Drag and drop the
OPC UA Call
node from the palette to your workspace - Connect an Inject node to provide input parameters to the Call node
- Add a Debug node after the Call node to see the results
Your flow should look like this:
[Inject] → [OPC UA Call] → [Debug]
step 2: configure the Call node
-
double-click the Call node to open its configuration dialog
-
set the Node name (optional):
Name: Start Process Method
-
configure the endpoint:
- select an existing endpoint from the dropdown, or
- Click the pencil icon to create/edit an endpoint
- example endpoint:
opc.tcp://localhost:4334
-
set the ObjectId (the object that contains the method):
ObjectId: ns=2;s=ProcessController
-
set the MethodId (the method to call):
MethodId: ns=2;s=StartProcess
-
click the Check button to validate the method and load argument definitions
-
click Done to save the configuration
step 3: Configure Input Parameters
-
couble-click the Inject node to configure method input arguments
-
cet the payload with the method parameters:
msg.payload = {
"processId": "PROC_001",
"targetTemperature": 150.0,
"duration": 3600
} -
configure method identifiers (if not set in Call node):
msg.objectId = "ns=2;s=ProcessController";
msg.methodId = "ns=2;s=StartProcess";
step 4: Deploy and Test
- click Deploy to deploy your flow
- click the Inject node button to trigger the method call
- check the Debug panel for the method results
Expected output:
{
"payload": {
"success": true,
"processHandle": 12345,
"estimatedCompletion": "2024-01-15T16:00:00Z"
},
"statusCode": "Good",
"objectId": "ns=2;s=ProcessController",
"methodId": "ns=2;s=StartProcess"
}
configuration options
node name
A friendly name for the node that appears in the flow editor. This helps identify the purpose of the method call.
endpoint
The OPC UA server connection that defines which server the node will connect to for method calls.
objectId
The NodeId of the object that contains the method. This identifies the context or parent object for the method execution.
formats:
- Numeric:
ns=2;i=1001
- String:
ns=2;s=ProcessController
- GUID:
ns=2;g=12345678-1234-1234-1234-123456789abc
- Browse Path:
/Objects/ProcessControllers/Controller1
methodId
The NodeId of the method to call. This identifies the specific function to execute.
formats:
- Numeric:
ns=2;i=2001
- String:
ns=2;s=StartProcess
- GUID:
ns=2;g=87654321-4321-4321-4321-210987654321
- Browse Path:
/Objects/ProcessControllers/Controller1/StartProcess
argument definition validation
The Check button validates the method definition and loads:
- Input Arguments: Required parameters for the method
- Output Arguments: Values returned by the method
It also populates the input fields with the expected argument names and types, making it easier to configure the method call.
input message formats
basic Method call
msg = {
payload: {
"parameter1": "value1",
"parameter2": 42,
"parameter3": true
},
objectId: "ns=2;s=MyObject", // Optional if configured in node
methodId: "ns=2;s=MyMethod" // Optional if configured in node
}
method Call with complex parameters
msg = {
payload: {
"processConfig": /* Extension object */
{
TypeId: "ns=2;s=ProcessConfigDatacType",
Body: {
"Temperature": 150.0,
"Pressure": 2.5,
"Duration": 3600,
"Materials": ["MaterialA", "MaterialB"]
}
},
"operatorId": "OP001",
"priority": "High"
},
objectId: "ns=2;s=ProcessController",
methodId: "ns=2;s=ConfigureProcess"
}
method Call with array parameters
msg = {
payload: {
"setpoints": [25.0, 30.0, 35.0, 40.0],
"durations": [600, 900, 1200, 600],
"enabled": true
},
objectId: "ns=2;s=TemperatureController",
methodId: "ns=2;s=SetProfile"
}
output Message format
The Call node outputs a message containing the method execution results:
{
// Original input properties
objectId: "ns=2;s=ProcessController",
methodId: "ns=2;s=StartProcess",
// Method execution results
payload: {
"outputParam1": "result1",
"outputParam2": 123,
"outputParam3": true
},
statusCode: "Good" // Method execution status
}
Status Codes
- Good: Method executed successfully
- BadMethodInvalid: Method not found or invalid
- BadTooManyOps: Server too busy to execute method
- BadInvalidArgument: Invalid input arguments provided
- BadUserAccessDenied: Insufficient permissions to call method
- BadMethodNotCallable: Method exists but is not callable