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
Rresults[] (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