Server API reference ==================== Server Constructor ------------------ To create a need to call new function 'newServer' from 'opcua' module. .. function:: 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. .. code:: lua config = { bufSize = 16384, securePolicies ={ { securityPolicyUri = "http://opcfoundation.org/UA/SecurityPolicy#None" } } endpointUrl = "opc.tcp://[hostname|ip]:4841"" } :return: server object Server default configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: examples/server/server_getting_started.lua :language: lua :lines: 1-6 `Full source <_static/server/server_getting_started.lua>`__ Server custom configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: examples/server/server_value_callback.lua :language: lua :lines: 4,8-23 `Full source <_static/server/server_value_callback.lua>`__ server:initialize ----------------- .. function:: 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. .. function:: server:run() :return: error server:shutdown --------------- This method stops the server and closes all connections. .. function:: server:shutdown() :return: nil server:addNodes --------------- Add new nodes to server address space. .. function:: 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 :ref:`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. .. function:: server:browse() :NodeId: Browse one node by NodeId. :NodeId[]: Array of NodeIds to browse. :parameters: Table with detailed parameters. For details see :ref:`browsing_detailes_parameters` server:read ----------- Read attibutes values of nodes. .. function:: server:read() :NodeId: (:ref:`node_id_type`) Read possible attributes of one node by NodeId. :NodeId[]: (:ref:`node_id_type`) Array of NodeIds to read. Will be read all possible attributes :parameters: (table) Table with detailed parameters. For details see :ref:`read_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** (:ref:`data_value_type`) The value of the attribute. The value will be nil in case of error. server:write ------------ .. function:: 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 :ref:`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 :ref:`custom_data_source` .. function:: 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.