Client API reference ==================== Constructor ----------- A client is created by calling: .. function:: ua.newClient() :config: Configuration table. If **nil** then default configuration is used with the following options: * One secure policy **None** * Endpoint URL *opc.tcp://:4841*. IP address is detected automatically and if failed then **localhost** is used. Example: .. literalinclude:: examples/client/client_connect.lua :language: lua :lines: 1-14 `Full source <_static/client/client_connect.lua>`__ Client configuration table ~~~~~~~~~~~~~~~~~~~~~~~~~~ **config** - a table with the following: **applicationName** (string) The client's application name **applicationUri** (string) application URI **productUri** Product URI **securePolicies** (table) List of polices that is used to secure messages See the :ref:`config_table` for details. **cosocketMode** (bool) Flag that sets client in cosockets mode aka asynchronous mode. **bufferSize** (uint32, optional,default=8192) Size of internal buffer used for sending and receiving messages. **logging** (table, optional) Optional client logging. No logging is performed if not set. See the :ref:`config_table` for details. Example: .. literalinclude:: examples/client/client_connect.lua :language: lua :lines: 3-12 `Full source <_static/client/client_connect.lua>`__ client:connect -------------- Establish connection to a server. .. function:: client:connect(endpointUrl[, transportProfile][, connectCallback]) :endpointUrl: (string) OPCUA server endpoint URL. it is possible to use the following formats: * opc.tcp://hostname:port/path * opc.http://hostname:port/path * opc.https://hostname:port/path Some servers might require 'http(s)://' scheme instead of 'opc.http(s)://'. :transportProfile: (string) Transport profile to use. It is defines encoding of sending and receiving messages. There are two kinds of encoding is possible to specify: binary and JSON. This parameter is omitted client will use binary encoding. Possible values: * ua.TranportProfileUri.TcpBinary is used wotn 'opc.tcp' scheme * ua.TranportProfileUri.HttpsBinary * ua.TranportProfileUri.HttpsJon :connectCallback: function that will be called on success or error. :return: error Example: .. literalinclude:: examples/client/client_connect_callback.lua :language: lua :lines: 17-34 `Full source <_static/client/client_connect_callback.lua>`__ Example without callback: .. literalinclude:: examples/client/client_connect.lua :language: lua :lines: 14-22 `Full source <_static/client/client_connect.lua>`__ Example of connecting to server over HTTP and with JSON encoding: .. literalinclude:: examples/client/client_connect_https_json.lua :language: lua :lines: 16-22 `Full source <_static/client/client_connect_https_json.lua>`__ client:openSecureChannel ------------------------ Open new secure channel. The client must open at least one channel. .. function:: client:openSecureChannel(timeout[, msgCallback]) :timeout: (uint32) How long a channel should be alive/active (in milliseconds). :msgCallback: `Message callback`_ :return: :ref:`openSecureChannelResponse`, error The client instance will automatically refresh when the channel has been established. Callback example: .. literalinclude:: examples/client/client_open_secure_channel_callback.lua :language: lua :lines: 16-42 `Full source <_static/client/client_open_secure_channel_callback.lua>`__ Blocking example (no callback): .. literalinclude:: examples/client/client_open_secure_channel.lua :language: lua :lines: 26-31 `Full source <_static/client/client_open_secure_channel.lua>`__ client:findServers ------------------ Get the list of the servers known to a Server or Discovery Server .. function:: client:findServers(params[, msgCallback]) :params: table with fields: **endpointUrl** (string, optional) Endpoint URL. **localeIds[]** (string, optional) List of locales to use. The Server should return the applicationName in the ApplicationDescription using one of locales specified. **serverUris[]** (string, optional) The List of servers to return. All known servers are returned if the list is empty. **msgCallback** - `Message callback`_ **Result**: :ref:`findServersResponse`, error Example: .. literalinclude:: examples/client/client_find_servers.lua :language: lua :lines: 32-50 `Full source <_static/client/client_find_servers.lua>`__ client:getEndpoints ------------------- Returns the Endpoints supported by a Server and all of the configuration information required to establish a SecureChannel and a Session. .. function:: client:getEndpoints(params[, msgCallback]) :params: a table with the following fields: **endpointUrl** (string, optional) The network address the Client used when accessing the DiscoveryEndpoint. **localeIds[]** (string, optional) List of locales to use. Specifies the locale to use when returning human readable strings. **profileUris[]** (string, optional) List of Transport Profiles that the returned Endpoints support. :msgCallback: `Message callback`_ :return: :ref:`getEndpointsResponse`,error Example: .. literalinclude:: examples/client/client_get_endpoints.lua :language: lua :lines: 32-50 `Full source <_static/client/client_get_endpoints.lua>`__ client:createSession -------------------- This Service is used by an OPC UA Client when creating a Session. The Server returns two values which uniquely identifies the Session. .. function:: client:createSession(name, timeoutMs[, msgCallback]) :params: a table with the following fields: **name** (string) Human readable string identifying the Session. **timeoutMs** (double) Requested maximum number of milliseconds that a Session should remain open without activity. :msgCallback: `Message callback`_ :return: :ref:`createSessionResponse`, error Example: .. literalinclude:: examples/client/client_create_session.lua :language: lua :lines: 35-44 `Full source <_static/client/client_create_session.lua>`__ client:activateSession ---------------------- Activate previously created session. Is used to authenticate user on the server. .. function:: client:activateSession(policyId [, identity, secret] [, msgCallback]) :policyId: (string) Token policy to use. This is taken from the server's endpoint description. Endpoint description can be obtained by calling :ref:`client:getEndpoints` or :ref:`client:createSession`. :identity: (string) User identity: `username`, `user certificate`, 'user token' Empty if token policy is anonymous. :secret: (string) User secret. 'password', 'user private key Empty if token policy is anonymous or an issued token. :msgCallback: `Message callback`_ :return: :ref:`activateSessionResponse`, error Example: .. literalinclude:: examples/client/client_create_session.lua :language: lua :lines: 48-52 `Full source <_static/client/client_create_session.lua>`__ client:browse ------------- This Service is used for discovering the References of a specified Node. .. function:: client:browse([nodeId | nodeId[] | params] [, msgCallback]) :nodeId: (:ref:`NodeId`) id of the node to browse. :nodeId[]: (:ref:`NodeId`) array of NodeIDs to browse :params: (table) :ref:`browseParameters` :msgCallback: `Message callback`_ :Result: :ref:`Browsing Result`,error Example: .. literalinclude:: examples/client/client_browse.lua :language: lua :lines: 52-67 `Full source <_static/client/client_browse.lua>`__ client:read ----------- Read one or more Attributes of one or more Nodes. .. function:: client:read( [, msgCallback]) :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 with detailed parameters. For details see :ref:`read_attributes` :msgCallback: `Message callback`_ :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** The value of the attribute. The value will be nil in case of error. Example: .. literalinclude:: examples/client/client_read.lua :language: lua :lines: 50-57 `Full source <_static/client/client_read.lua>`__ client:write ------------ This Service is used when writing values to one or more Attributes of one or more Nodes. .. function:: client:write(params[, msgCallback]) :params: (table) **NodesToWrite[]** (array) **NodeId** (:ref:`NodeId`) node identifier **AttributeId** (:ref:`attribute`) attribute to read **Value** (:ref:`DataValue`) New value of attribute :msgCallback: `Message callback`_ :return: :ref:`writeResponse`,error Example: .. literalinclude:: examples/client/client_write.lua :language: lua :lines: 45-67 `Full source <_static/client/client_write.lua>`__ client:addNodes --------------- Add one or more Nodes into the AddressSpace hierarchy. .. function:: client:addNodes(parameters[, msgCallback]) :parameters: (table) A table with array of nodes to add. See details in :ref:`Adding Nodes` :msgCallback: `Message callback`_ :return: :ref:`addNodesResponse`,error Example: .. literalinclude:: examples/client/client_add_nodes.lua :language: lua :lines: 84-106 `Full source <_static/client/client_add_nodes.lua>`__ client:translateBrowsePaths --------------------------- This Service is used when requesting that the Server translates one or more browse paths to NodeIds. .. function:: client:translateBrowsePaths(params[, msgCallback]) :msgCallback: `Message callback`_ client:closeSession ------------------- Terminate an active Session. .. function:: client:closeSession([msgCallback]) :msgCallback: `Message callback`_ :return: :ref:`closeSessionResponse`,error Example: .. literalinclude:: examples/client/client_create_session.lua :language: lua :lines: 55-58 `Full source <_static/client/client_create_session.lua>`__ client:closeSecureChannel ------------------------- Terminate a SecureChannel. .. function:: client:closeSecureChannel() :return: :ref:`closeSecureChannelResponse`,error client:disconnect ----------------- Close the client's server socket connection. Calling this method also closes any open channel. .. function:: client:disconnect() :return: error Message callback ---------------- Callback function that is called when the request has been completed. .. function:: msgCallback(response, err) :response: Data received from server in response to corresponding request. :err: Any error that occured during processing of request.