Server API reference
Server Constructor
To create a need to call new function ‘newServer’ from ‘opcua’ module.
- ua.newServer([config])
- config:
table with configuration options.
If not provided, default configuration will be used. in this case host name for endpoint will be automatically detected. Server will listen on port 4841.
config = { bufSize = 16384, securePolicies ={ { securityPolicyUri = "http://opcfoundation.org/UA/SecurityPolicy#None" } } endpointUrl = "opc.tcp://[hostname|ip]:4841"" }
- return:
server object
Server default configuration
-- Load the OPCUA API module
local ua = require("opcua.api")
-- Create new OPC UA server instance.
-- Pass configuration table to server.
local server = ua.newServer()
Server custom configuration
local ua = require("opcua.api")
local config = {
endpoints = {
{
endpointUrl = "opc.tcp://localhost:4845",
}
},
securePolicies = {
{ -- #1
securityPolicyUri = ua.Types.SecurityPolicy.None,
},
},
}
local server = ua.newServer(config)
server:initialize
- server:initialize()
This method initializes internal server structures and becomes ready for customizations: adding nodes, setting variable sources, writing values, etc.
- return:
nil
server:run
This method opens a server socket and starts listening for incoming connections.
- server:run()
- return:
error
server:shutdown
This method stops the server and closes all connections.
- server:shutdown()
- return:
nil
server:addNodes
Add new nodes to server address space.
- server:addNodes(parameters)
- parameters:
A table with a field NodesToAdd. NodesToAdd is an array of tables with the parameters of new nodes. For details see Adding Nodes
- return:
The result from an OPC UA call will be an array. Every element of the array will be a table with two fields: Status code for the current node and identifier of the added node.
Every element of the array contains a table with the following fields:
- StatusCode
The status code from adding the corresponding node.
- AddedNodeId
Identifier of added node. The server automatically assigns an identifier for the node if not included. The identifier will be nil in case of error.
server:browse
Browse nodes in the server address space.
- server:browse(<NodeId | NodeId[] | parameters>)
- NodeId:
Browse one node by NodeId.
- NodeId[]:
Array of NodeIds to browse.
- parameters:
Table with detailed parameters. For details see Detailed Parameters
server:read
Read attibutes values of nodes.
- server:read(<NodeId | NodeId[] | parameters>)
- NodeId:
(NodeID) Read possible attributes of one node by NodeId.
- NodeId[]:
(NodeID) Array of NodeIds to read. Will be read all possible attributes
- parameters:
(table) Table with detailed parameters. For details see Reading Attributes
- return:
The result from an OPC UA call will be an array. Every element of the array will be a table with two fields: Status code for the current node and the value of the attribute.
Every element of the array contains a table with the following fields:
- StatusCode
The status code from reading the corresponding node.
- Value (DataValue)
The value of the attribute. The value will be nil in case of error.
server:write
- server:write(parameters)
- parameters:
A table with a field NodesToWrite. NodesToWrite is an array of tables with the parameters of nodes to write. For details see Writing Attributes
- return:
response, error
- response
array if error is nil The result from an OPC UA call will be an array. Every element of the array is Status code for the each node node
nil id StatusCode is not nil
- error
StatusCode of operation overall or nil
server:setVariableSource
This method sets a callback function for a variable node. The callback function will be called when the value of the variable is reading or writing. For more details, see Exporting Device Data
- server:setVariableSource(nodeId, callback)
- nodeId:
NodeId of the variable node.
- callback:
Function to be called when the value of the variable is being read or write.