Data Types
This page summarizes the Lua representations used by the OPC UA stack. Values are ordinary Lua values unless a table structure is shown.
Built-in Types
OPC UA type |
Lua representation |
Notes |
|---|---|---|
|
number |
Signed 8-bit integer. |
|
number |
Unsigned 8-bit integer. |
|
number |
Signed 16-bit integer. |
|
number |
Unsigned 16-bit integer. |
|
number |
Signed 32-bit integer. |
|
number |
Unsigned 32-bit integer. |
|
number |
Signed 64-bit integer. |
|
number |
Unsigned 64-bit integer. |
|
number |
32-bit floating-point value. |
|
number |
64-bit floating-point value. |
|
number |
Unix timestamp in seconds, usually from |
|
string |
UTF-8 string. |
|
string |
Binary byte sequence stored in a Lua string. |
|
string |
GUID string, for example |
|
number |
OPC UA status code, for example |
LocalizedText
Localized text is represented as a table.
Field |
Type |
Description |
|---|---|---|
|
string, optional |
Locale name such as |
|
string |
Localized text content. |
local text = {Locale = "en-US", Text = "This is localized text"}
local textDefaultLocale = {Text = "This is localized text"}
QualifiedName
A QualifiedName is the service identifier of a node. It combines a namespace index with a name.
Field |
Type |
Description |
|---|---|---|
|
number |
Namespace index. |
|
string |
Name within the namespace. |
local qualifiedName = {ns = 1, Name = "Node Name"}
NodeId
A NodeId is encoded as a string:
[ns=<namespace_index>;]<type>=<value>
Part |
Value |
Description |
|---|---|---|
|
unsigned 16-bit integer |
Optional. Omit when the namespace index is |
|
|
Identifier type: integer, string, GUID, or opaque byte string. |
|
type-specific string |
Decimal integer, UTF-8 string, lowercase GUID, or base64 byte string. |
Type code |
Identifier type |
Example |
|---|---|---|
|
Integer |
|
|
String |
|
|
GUID |
|
|
Opaque byte string |
|
Additional examples are available in node_id.lua. The official syntax is described in the OPC Foundation NodeId reference.
NodeId helpers
Function |
Parameters |
Return value |
|---|---|---|
|
|
Encoded NodeId string. |
|
Table form of the same parameters. |
Encoded NodeId string. |
|
Encoded NodeId string. |
Table with |
Variant
A Variant wraps a value with an OPC UA type. It can represent a scalar or an array.
Field |
Type |
Description |
|---|---|---|
|
|
Type of the stored value. |
|
any supported Lua value |
Value to encode. |
|
boolean, optional |
Set to |
|
number array, optional |
Dimensions for array values. |
local uint32 = {Type = ua.VariantType.UInt32, Value = 0}
local uint32Array = {
Type = ua.VariantType.UInt32,
Value = {1, 2, 3, 4},
IsArray = true,
ArrayDimensions = {4}
}
VariantType constants
Name |
Value |
Name |
Value |
|---|---|---|---|
|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
DataValue
A DataValue is a Variant value plus optional status and timestamp fields.
Field |
Type |
Description |
|---|---|---|
|
|
Type of |
|
any supported Lua value |
Value to encode. |
|
status code, optional |
Value status, for example |
|
DateTime, optional |
Source timestamp. |
|
DateTime, optional |
Server timestamp. |
|
UInt16, optional |
Fractional source timestamp precision. |
|
UInt16, optional |
Fractional server timestamp precision. |
local dataValue = {
Type = ua.VariantType.UInt32,
Value = 100,
StatusCode = ua.StatusCode.Good,
SourceTimestamp = os.time()
}
TimestampsToReturn
ua.TimestampsToReturn selects which timestamps the Server includes in
returned DataValues.
Constant |
Value |
Description |
|---|---|---|
|
0 |
Return the source timestamp only. |
|
1 |
Return the server timestamp only. |
|
2 |
Return both source and server timestamps. |
|
3 |
Do not return source or server timestamps. |
MonitoringMode
ua.MonitoringMode controls whether a MonitoredItem samples and reports
values.
Constant |
Value |
Description |
|---|---|---|
|
0 |
Do not sample or report values. |
|
1 |
Sample and queue values without reporting them. |
|
2 |
Sample, queue, and report values through Publish responses. |
DataChangeTrigger
ua.DataChangeTrigger selects which DataValue changes create notifications.
Constant |
Value |
Description |
|---|---|---|
|
0 |
Report changes to the StatusCode. |
|
1 |
Report changes to the StatusCode or value. |
|
2 |
Report changes to the StatusCode, value, or source timestamp. |
DeadbandType
ua.DeadbandType selects how a DataChangeFilter suppresses small value
changes.
Constant |
Value |
Description |
|---|---|---|
|
0 |
Do not apply a deadband. |
|
1 |
Require an absolute difference greater than |
|
2 |
Require a percentage difference based on the Variable’s engineering range. The compact Server does not support this mode. |
ExtensionObject
An ExtensionObject represents a structured value. It is also used when a field
can contain one of several structure types, such as node attributes for
AddNodes.
Field |
Type |
Description |
|---|---|---|
|
NodeId of the structure type. This is the decoded structure NodeId, not the binary, XML, or JSON encoding NodeId. |
|
|
table, ByteString, XML string, or JSON string |
Decoded body table when the structure is known. Otherwise, the body is left opaque and must be decoded by application code. |
local extensionObject = {
TypeId = "i=338", -- BuildInfo
Body = {
ProductUri = ua.Version.ProductUri,
ManufacturerName = ua.Version.ManufacturerName,
ProductName = ua.Version.ProductName,
SoftwareVersion = ua.Version.Version,
BuildNumber = ua.Version.BuildNumber,
BuildDate = compat.gettime()
}
}
Service Structures
NotificationData
NotificationMessage.NotificationData is an array of
ExtensionObject notification payloads returned by
both Publish and Republish responses. The array is empty when the
NotificationMessage is a keep-alive.
A data-change notification is an ExtensionObject with TypeId = "i=811".
Its Body contains:
Field |
Type |
Description |
|---|---|---|
|
array |
Values reported for the MonitoredItems that produced notifications. |
|
UInt32 |
Application-defined handle supplied in the MonitoredItem’s
|
|
Sampled value, StatusCode, and requested timestamps. |
|
|
array |
Optional diagnostics corresponding to |
ResponseHeader
Every OPC UA service response contains a ResponseHeader with service-level status and diagnostic information.
Field |
Type |
Description |
|---|---|---|
|
DateTime |
Server time when the response was created. |
|
UInt32 |
Handle copied from the corresponding request. The Client uses it to associate asynchronous responses with callbacks. |
|
StatusCode |
Overall result of the service call. Per-operation failures can still be
present in a successful response’s |
|
DiagnosticInfo |
Service-level diagnostic details. String indexes in this structure refer
to entries in |
|
String array |
Strings referenced by indexes in |
|
Additional service-defined response data. A null ExtensionObject means that no additional header was supplied. |
ActivateSessionResponse
Field |
Type |
Description |
|---|---|---|
|
ByteString |
Random value that should not be reused. |
|
StatusCode array |
User identity token validation results. |
AddNodesResponse
Field |
Type |
Description |
|---|---|---|
|
array |
One result per requested node. |
|
StatusCode |
Status of the add operation. |
|
Server-assigned NodeId, or |
BrowseParameters
Field |
Type |
Description |
|---|---|---|
|
UInt32 |
Maximum number of references to return. |
|
array |
Nodes to browse. |
|
Node to browse. |
|
|
Reference type to follow. |
|
|
|
Browse direction. |
|
|
Node classes to include. |
|
|
Fields to include in the response. |
|
boolean |
Include subtypes of |
BrowseResult
Field |
Type |
Description |
|---|---|---|
|
array |
One result per requested node. |
|
StatusCode |
Browse status for the requested node. |
|
array |
References returned by the browse operation. |
|
Target node identifier. |
|
|
Reference type identifier. |
|
|
boolean |
Reference direction. |
|
Service name of the node. |
|
|
User-facing node label. |
|
|
Int32 |
Node class. |
|
Node type definition. |
CloseSecureChannelResponse
Empty table.
CloseSessionResponse
Empty table.
CreateSessionResponse
Field |
Type |
Description |
|---|---|---|
|
Standard OPC UA response header. |
|
|
Unique NodeId assigned by the server to the session. |
|
|
Unique token assigned by the server to the session. |
|
|
Double |
Actual maximum session idle time in milliseconds. |
|
ByteString |
Random value that should not be reused in another request. |
|
ByteString |
Server application instance certificate. |
|
array |
Endpoint descriptions supported by the server. |
|
table |
Signature generated with the server certificate private key. |
|
UInt32 |
Maximum request body size in bytes. |
FindServersResponse
Field |
Type |
Description |
|---|---|---|
|
array |
Servers that match the request criteria. |
|
string |
Application URI. |
|
string |
Product URI. |
|
Human-readable application name. |
|
|
number |
OPC UA application type. |
|
string |
Gateway server URI, if used. |
|
string |
Discovery profile URI, if used. |
|
string array |
Discovery endpoint URLs. |
GetEndpointsResponse
Field |
Type |
Description |
|---|---|---|
|
array |
Endpoint descriptions. |
|
string |
Endpoint URL. |
|
table |
Server application description. |
|
ByteString |
Server certificate. |
|
number |
Message security mode. |
|
string |
Security policy URI. |
|
array |
Supported user identity token policies. |
|
string |
Transport profile URI. |
|
Byte |
Relative endpoint security level. |
OpenSecureChannelResponse
Field |
Type |
Description |
|---|---|---|
|
Standard OPC UA response header. |
|
|
table |
Secure channel token. |
|
UInt32 |
Unique SecureChannel identifier. |
|
UInt32 |
Unique token identifier within the channel. |
|
DateTime |
Token creation time. |
|
UInt32 |
Token lifetime in milliseconds. |
ReadResponse
Field |
Type |
Description |
|---|---|---|
|
DataValue array |
Attribute values returned by the server. |
WriteResponse
Field |
Type |
Description |
|---|---|---|
|
StatusCode array |
Results for the nodes written by the request. |