Data Types¶
Node Identifiers (NodeID)¶
A Node identifier is encoded as a string with the following syntax:
[ns=<namespace_index>;]<type>=<value>
- namesace_index
Unsigned 16-bit integer. Should be omitted if the namespace is zero.
- type
The Identifier’s type encoded as a string:
i - Integer
s - string
g - GUID
b - opaque byte string
- value
Identifier encoded as string depending on type:
i - In decimal form
s - UTF-8 string
g - GUID with small letters of hexademical numbers
b - opaque base64 encoded string.
Examples:
-- integer with namespace index 1. local numberNode = 'ns=1;i=100' -- By default, namespace is zero local numberNode = 'i=100' -- String local stringNode = 'ns=1;s=string' local stringNode = 's=string' -- Guid local guidNode = 'ns=100;g=00000001-0002-0003-0405-060708090a0b' local guidNode = 'g=00000001-0002-0003-0405-060708090a0b' --ByteString local byteStringNodeId = 'b=iuZVz8N6YulzlqYeA+P7qAGDCX8Wj1uxon37fqROcqc=' --ByteString with non zero namespace index local byteStringNodeId = 'ns=1;b=iuZVz8N6YulzlqYeA+P7qAGDCX8Wj1uxon37fqROcqc='
Additional details can be found in the official OPCUA reference
Encoding and decoding NodeID string notation¶
- toString(id, ns)
- id - identifier value: can be number, string, GUID, array or bytesns - namespace index number or nilreturns string with encoded NodeID
- toString( {id=<value>[, ns=<number>]} )
- id - identifier value: can be number, string, GUID, array oy bytes.ns - namespace index number or nil.returns string with encoded NodeID
Examples:
local nodeId = require("opcua.node_id") -- Numeric -- 'i=100' local nodeIdString = nodeId.toString(100) local nodeIdString = nodeId.toString({id=100}) -- 'ns=1;i=100' local nodeIdString = nodeId.toString(100, 1) local nodeIdString = nodeId.toString({id=100, 1}) -- String -- 's=hello' local nodeIdString = nodeId.toString('hello') local nodeIdString = nodeId.toString({id='hello'}) -- 'ns=1;s=hello' local nodeIdString = nodeId.toString('hello', 1) local nodeIdString = nodeId.toString({id='hello', ns=1}) -- GUID local guid = { data1 = 1, data2 = 2, data3 = 3, data4 = 4, data5 = 5, data6 = 6, data7 = 7, data8 = 8, data9 = 9, data10 = 10, data11 = 11 } -- 'g=00000001-0002-0003-0405-060708090a0b' local nodeIdString = nodeId.toString(guid) local nodeIdString = nodeId.toString({id=guid}) -- 'ns=1;g=00000001-0002-0003-0405-060708090a0b' local nodeIdString = nodeId.toString(guid, 1) local nodeIdString = nodeId.toString({id=guid, ns=1}) -- ByteString -- 'b=AQIDBAUGBw==' local nodeIdString = nodeId.toString({1,2,3,4,5,6,7}) local nodeIdString = nodeId.toString({id={1,2,3,4,5,6,7}}) -- 'ns=1;b=AQIDBAUGBw==' local nodeIdString = nodeId.toString({1,2,3,4,5,6,7}, 1) local nodeIdString = nodeId.toString({id={1,2,3,4,5,6,7}, ns=1})
- fromString(string)
- string - encoded NodeIDreturn - table with fields: ns - namepsace index, id - value
Examples:
local nodeId = require("opcua.node_id") -- Numeric -- {id=100} local nodeIdtbl = nodeId.fromString('i=100') -- {id=100,ns=1} local nodeIdtbl = nodeId.fromString('ns=1;i=100') -- String -- {id='hello'} local nodeIdtbl = nodeId.toString('s=hello') -- {id='hello', ns=1} local nodeIdtbl = nodeId.toString('ns=1;s=hello') -- GUID -- guid = { -- data1 = 1, data2 = 2, data3 = 3, -- data4 = 4, data5 = 5, data6 = 6, -- data7 = 7, data8 = 8, data9 = 9, -- data10 = 10, data11 = 11 -- } -- -- nodeIdtbl = {id = guid} local nodeIdtbl = nodeId.fromString('g=00000001-0002-0003-0405-060708090a0b') -- 'ns=1;g=00000001-0002-0003-0405-060708090a0b' local nodeIdtbl = nodeId.fromString('ns=1;g=00000001-0002-0003-0405-060708090a0b') -- ByteString -- byteString = {1,2,3,4,5,6,7} -- {id=byteString} local nodeIdtbl = nodeId.toString('b=AQIDBAUGBw==') -- {id={1,2,3,4,5,6,7}, ns=1} local nodeIdtbl = nodeId.fromString('ns=1;b=AQIDBAUGBw==')
Variant¶
All values in OPC-UA can be represented with the universal data structure Variant. Variants can represent either a scalar value or a multidimensional array. Multidimensional arrays can only be of one type in Lua. A Variant is represented as a table with one field, where the key defines type of the value stored in the table.
Variant example¶
local uint32 = {
UInt32 = 0
}
local uint32_array = {
uint32 = {1,2,3,4,5,6,7}
}
local localized_text = {
localizedText = {
locale = "en-US",
text = "This is a text string"
}
}
local localized_text_array = {
localizedText = {
{ #1
locale = "en-US",
text = "This is a text string"
},
{ #2
text = "This is a text string without locale"
}
}
}
The fields you may set in a Variant table¶
byte
sbyte
int16
uint16
int32
uint32
int64
uint64
float
double
dateTime
guid
localizedText
qualifiedName
nodeId
statusCode
string
qualifiedName
dataValue
variant
extensionObject
OPC-UA Types¶
- sbyte
Signed 8-bit integer
- byte
Unsigned 8-bit integer
- int16
Signed 16-bit integer
- uint16
Unsigned 16-bit integer
- int32
Signed 32-bit integer
- uint32
Unsigned 32-bit integer
- int64
Signed 64-bit integer
- uint64
Unsigned 64-bit integer
- float
Real 32-bit number
- double
Real 64-bit number
- DateTime
Real 64-bit number. Represents milliseconds since Jan. 1, 1970.
- String
String.
- Guid
Guid in form of table:
local guid = { data1 = 0x123456, -- uint32 data2 = 0x1234, -- uint16 data3 = 0x1234, -- uint16 data4 = 0x23, -- byte data5 = 0x23, -- byte data6 = 0x21, -- byte data7 = 0x21, -- byte data8 = 0x21, -- byte data9 = 0x21, -- byte data10 = 0x21, -- byte data11 = 0x21 -- byte }TBD - String representaion
- LocalizedText
- Localized text. A table with two fields:
locale - optional locale name. The default locale is used if nil
text - string with content
Example:
local localizedText = { locale = "en-US", text = "This is localized text" } local localizedText = { text = "This is localized text" }
- QualifiedName
Qualified Name is the service identifier of a node, which consist of a namespace index and text label.
local qualifiedName = { nsi = 1, name = "Node Name" }- NodeID
Identifier of a node. Explaned in Node Identifiers (NodeID)
- StatusCode
Error code.
- DataValue
Complete variable value.
local dataValue = { value = {uint32 = 100}, -- Variant(v.Value) statusCode = ua.StatusCode.Good, -- StatusCode (Optional) sourceTimestamp = os.time(), -- DateTime (Optional) serverTimestamp = os.time(), -- DateTime (Optional) sourcePicoseconds = 0, -- UInt16 (Optional) serverPicoseconds = 0, -- UInt16 (Optional) }- Variant
Explained in section Variant
- ExtensionObject
Any data type that can be encoded with OPC-UA encoding schemas (binary, XML, Json).
local extensionObject = { typeId = "i=7617", -- (NodeId) DataType node that represent encoding. body = {0,1,2,3,4,5} -- (ByteString) Encoded value (binary, XML, JSON) }
activateSessionResponse¶
- serverNonce
A random number that should not be reused.
- results[]
list of SatusCodes
addNodesResponse¶
results[] (array)
- statusCode
StatusCode for the added Node
- addedNodeId
Server assigned NodeId for the added Node. The NodeId is nil if the operation failed.
browseParameters¶
- RequestedMaxReferencesPerNode
Maximum number of reference types that will be processed. Zero - unlimited
- NodesToBrowse[] Array of nodes to browse:
- NodeId (NodeId)
The identifier of a node to browse
- ReferenceTypeId NodeId
Reference type identifier
- BrowseDirection ua.Types.BrowseDirection
Browsing direction
- nodeClassMask ua.Types.NodeClass
The class of nodes to include in the response
- ResultMask ua.Types.BrowseResultMask
A mask that specifies the set of data to include in the response
- IncludeSubtypes Boolean
If 1 then all subtypes of the specified ReferenceTypeId will be followed
browseResult¶
- Results[] (array)
The result is provided as a Lua table. Every element index corresponds to an element in the request.
- StatusCode
The ‘status’ of browsing the requested node.
- References
Array of references.
- NodeId (NodeId)
Node identifier
- ReferenceTypeId (NodeId)
Reference type identifier
- IsForward (Boolean)
Browsing direction
- BrowseName (QualifiedName)
Service name of a node
- DisplayName (LocalizedText)
User labe of a node
- NodeClass (Int32)
Node class
- TypeDefinition (NodeId)
The node’s type definition
closeSecureChannelResponse¶
Empty table
closeSessionResponse¶
Empty table
createSessionResponse¶
responseHeader
- sessionId (Node Identifiers (NodeID))
A unique NodeId assigned by the Server to the Session.
- authenticationToken (Node Identifiers (NodeID))
A unique identifier assigned by the Server to the Session
- revisedSessionTimeout (double)
Actual maximum number of milliseconds that a Session shall remain open without activity.
- serverNonce (bytestring)
A random number that should never be used in any other request.
- serverCertificate
The Application Instance Certificate issued to the Server
- serverEndpoints
List of Endpoints that the Server supports.
- serverSignature
This is a signature generated with the private key associated with the serverCertificate.
- maxRequestMessageSize (uint32)
The maximum size, in bytes, for the body of any request message.
findServersResponse¶
- servers[]
List of Servers that meet criteria specified in the request.
applicationUri
productUri
applicationName
applicationType
gatewayServerUri
discoveryProfileUri
discoveryUrls
getEndpointsResponse¶
endpoints[]
endpointUrl
server
serverCertificate
securityMode
securityPolicyUri
userIdentityTokens
transportProfileUri
securityLevel
openSecureChannelResponse¶
responseHeader
- securityToken
- channelId (uint32)
A unique identifier for the SecureChannel.
- tokenId (uint32)
A unique identifier for a single SecurityToken within the channel.
- createdAt (dateTime)
The time when the SecurityToken was created.
- revisedLifetime (uint32)
The lifetime of the SecurityToken in milliseconds.
readResponse¶
- results[] (dataValue)
List of Attribute values
writeResponse¶
- results[] (statusCode)
List of results for the Nodes to write