Skip to main content

Add MonitoredItem

Prerequisite Reading

sub.add_node(...)​

def add_node(self,
node_id: str,
callback: Optional[Callable[[DataChangeEventArgs], None]] = None,
attribute: AttributeId = AttributeId.Value,
sampling_interval_ms: float = -1.0,
mode: MonitoringMode = MonitoringMode.Reporting,
queue_size: int = 1,
discard_oldest: bool = True,
filter: Optional[DataChangeFilter] = None) -> int: ...
ParametersDefaultNote
node_id—Monitored NodeId; Throws an empty string ( OpcUaException status = DarraInvalidArgument)
callbackNoneThis dedicated MI callback (the container-level data_changed event will still be triggered)
attributeValue (13)Monitored Attributes
sampling_interval_ms-1 (Subscribe)Server sampling interval. 0 = As soon as possible
modeReportingIf it is not "Reporting" after creation, automatically reschedule the synchronization set_mode once.
queue_size1Server queue length (>= 1); automatically recalibrates once when the value is not the default modify_item
discard_oldestTrueDrop Policy When the Queue Is Full (True = Drop the Oldest, False = Drop the Newest)
filterNoneDataChangeFilter; The current version will not actually be deployed to the server., See DataChangeFilter“” below

Returns: int MonitoredItem handle (local handle, used for subsequent modify / remove operations)

Exception: Thrown when the underlying layer DarraUa_Subscription_AddNode returns a non-0 value ( OpcUaException where status is the underlying primitive status code, such as BadNodeIdUnknown)

h1 = sub.add_node("ns=2;s=Temperature")
h2 = sub.add_node("ns=2;s=Pressure", sampling_interval_ms=100)

# With a dedicated callback
def on_temp(e):
print(f"Temperature: {e.value_string}")

h3 = sub.add_node("ns=2;s=Temperature2", callback=on_temp)

add_many​

Add RPC multiple items at once MI; in a loop, add_node add one item at a time MI RPC:

def add_many(self,
node_ids: List[str],
callback: Optional[Callable[[DataChangeEventArgs], None]] = None,
attribute: AttributeId = AttributeId.Value
) -> List[Tuple[int, StatusCode]]: ...

Returns each item (mi_handle, status) — failed items mi=0. Top-level: If a non-0 value is returned DarraUa_Subscription_AddNodes, the entire call throws an exception OpcUaException; a single item failure is reflected only status in that element’s return value and does not throw an exception.

nodes = [f"ns=2;s=T{i}" for i in range(1, 101)]
results = sub.add_many(nodes)
for nid, (mi, st) in zip(nodes, results):
if st == StatusCode.Good:
print(f" {nid} -> handle={mi}")
else:
print(f" {nid} FAILED: {st.name}")

Performance: add_many When DarraUa_Subscription_AddNodes adding N items at once MI, each item is processed once DarraUa_Subscription_AddNode; add_node when using a loop, each item is processed once MI per iteration. The actual time required depends on the server and network conditions.

Items added via DarraUa_Subscription_AddNode are not MI included in the self-recovery subscription.

add_many Added MI Not participatingSubscription Resumes Automatically — After the session reconnectsNot a single one will come back. Please add monitoring items that require automatic recovery one by one sub.add_node(...).

DataChangeEventArgs Fields​

Subscription callback parameters DataChangeEventArgs (dataclass, thread-safe):

FieldTypeNote
monitored_item_handleintTriggered MI Handle
node_idstrIt's about time MI NodeId
value_stringOptional[str]String representation of a value (pre-extracted, cross-thread safe)
data_type_nameOptional[str]Names of built-in data type enumerations (e.g., Double)
statusStatusCodeThe value OpcUaDataValue.status of the bottom layer
source_timestampOptional[datetime]Data Source Timestamp (UTC)
server_timestampOptional[datetime]Server Timestamp (UTC)
Security Design

value_string / data_type_name: Already implemented within the Publish callback threadSynchronous Extraction For Python strings and enumerations, thread-safe. Do not expose pointers to raw data values, to prevent crashes caused by references remaining after deallocation.

Remove​

sub.remove(handle)
sub.remove_by_node_id("ns=2;s=Temperature") # Press NodeId to remove all matching items

Monitoring Different Attributes​

attribute Accepts any member of the enumeration AttributeId (NodeId / NodeClass / BrowseName / DisplayName / Value / DataType / AccessLevel / EventNotifier / Executable ...). When monitoring a property other than Value, the in the callback is value_string the text representation of that property:

sub.add_node("ns=2;s=T1", attribute=AttributeId.Value)         # Default, Value Change
sub.add_node("ns=2;s=T1", attribute=AttributeId.AccessLevel) # Monitor Changes in Access Permissions
In the AttributeId

enumeration without a AttributeId .StatusCode OPC UANone StatusCode / Quality Members — The status code is not a node attribute; it is provided DataChangeEventArgs.status in along with every data change. If you want to "focus only on status changes," please use DataChangeFilter trigger=DataChangeTrigger.STATUS.

DataChangeFilter (Dead Zone)​

add_node The parameter filter accepts DataChangeFilter, butThe current version SDK will not push it to the server.:

  • The current version does not support the ability to push filters; filter Not in effect, Data is still reported in full according to the server's default rules.
  • If it doesn't take effect, send a push notification OpcUaEventCategory.Diagnostic / OpcUaEventSeverity.Warn event with the message: "This DataChangeFilter feature is not available in the current version."
  • The filter is passed only at creation time, After the subscription is restored, it won't be put back up.。

In other words: Passing a filter won't cause an error, nor will it result in any data being omitted, but dead-zone filtering is currently only declared and does not function. If you actually want to reduce the data volume, you'll need to perform numerical checks in the callback yourself.

Next Step​