Data Types

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.

ByteString

An array ot bytes. In LUA represented as 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 = {
  ns = 1,
  Name = "Node Name"
}

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='

Full source

Additional details can be found in the official OPCUA reference

Encoding and decoding

toString(id, ns)
id - identifier value: can be number, string, GUID, array or bytes
ns - namespace index number or nil
returns 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})

Full source

fromString(string)
string - encoded NodeID
return - 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==')

Full source

StatusCode

Error code.

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 Fields

  • Byte

  • Sbyte

  • Int16

  • UInt16

  • Int32

  • UInt32

  • Int64

  • UInt64

  • Float

  • Double

  • DateTime

  • Guid

  • LocalizedText

  • QualifiedName

  • NodeId

  • StatusCode

  • String

  • QualifiedName

  • DataValue

  • Variant

  • ExtensionObject

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"
    }
  }
}

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)
}

ExtensionObject

ExtensionObject is a structure that can be used to represent complex data structures.

Also it is used when the same field can be of different types.F or example there are different set of attributes for different types of nodes. In fhis case ExtensionObject a field with attributes can contain one of: ObjectAttributes, VariableAttributes, MethodAttributes, etc.

Extension objects represented as a table with two fields:

  • TypeId - NodeId of the type of the object

  • Body - A table with fields that represent the object’s data.

Note

If structure of is not known for current server/client then body considered to be opaque and can be one of the following types:

  • ByteString

  • XML string

  • JSON string

In this case parsing of body is not performed automatically and should be done manually by a developer

Example:

local extensionObject = {
  TypeId = {ns=0, id="i=1"},
  Body = {
    UInt32 = 100
  }
}

local extensionObject = {
  TypeId = {ns=0, id="i=1"},
  Body = {
    UInt32 = 100
  }
}

Note

The Body field can be any Variant type.

Requests

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 (NodeID)

A unique NodeId assigned by the Server to the Session.

AuthenticationToken (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