Skip to main content

Modify

Prerequisite Reading

sub.modify(...)​

Modify the publication parameters for a subscription (ModifySubscription service):

def modify(self,
publishing_interval_ms: float,
lifetime_count: int = 1200,
max_keep_alive_count: int = 50,
max_notifications_per_publish: int = 0,
priority: int = 0) -> ModifySubscriptionResult: ...
ParametersMeaning
publishing_interval_msTime Between New Releases
lifetime_countPublishRequest If I haven't received anything for a certain number of publication cycles, I'll cancel the subscription.
max_keep_alive_countHow often should a KeepAlive be sent when there is no new data?
max_notifications_per_publishWhat is the maximum number of notifications that can be sent in a single Publish operation? 0 = unlimited
priorityPriority (0–255)

Returns ModifySubscriptionResult:

FieldTypeNote
revised_publishing_interval_msfloatActual deployment interval on the server side
revised_lifetime_countintActual server lifetime
revised_max_keep_alive_countintActual server-side keepalive
rev = sub.modify(publishing_interval_ms=1000, lifetime_count=600, max_keep_alive_count=30)
print(f"Revised publishing interval = {rev.revised_publishing_interval_ms}ms")

priority If the value exceeds 0–255, it is truncated to the lower 8 bits. A exception is thrown if the server returns a non-0 value OpcUaException. Upon success, sub.publishing_interval_ms will beServer-side revision value Overwrite; at the same time, the lifetime and keepalive values are also written back to the local storage for use in rebuilding the subscription.

sub.modify_monitored_items(requests)​

Batch Edit MI Sampling Parameters (ModifyMonitoredItems Service):

def modify_monitored_items(
self,
requests: List[MonitoredItemModifyRequest]
) -> List[ModifyMonitoredItemResult]: ...

MonitoredItemModifyRequest Field:

FieldDefaultNote
monitored_item_handle—Local MI Handle
sampling_interval_ms-1.0-1 = Follow subscription, 0 = As soon as possible
queue_size1Server Buffer Queue Length
discard_oldestTrueTrue = Discard the oldest, False = Discard the newest

ModifyMonitoredItemResult:

FieldTypeNote
statusStatusCodeRevision Results
revised_sampling_interval_msfloatActual sampling interval on the server side
revised_queue_sizeintActual server queue size
from darra_opcua import MonitoredItemModifyRequest

requests = [
MonitoredItemModifyRequest(
monitored_item_handle=h,
sampling_interval_ms=50,
queue_size=10,
discard_oldest=True)
for h in mi_handles
]
results = sub.modify_monitored_items(requests)

If the server returns a non-0 value, the entire call is aborted OpcUaException; if a single item fails, it is reflected only in that element status, and no exception is thrown.

sub.modify_item(...) Single MI Simplified Version​

def modify_item(self,
monitored_item_handle: int,
sampling_interval_ms: float,
queue_size: int = 1,
discard_oldest: bool = True) -> ModifyMonitoredItemResult: ...
r = sub.modify_item(handle, sampling_interval_ms=50)
print(f"Revised sampling = {r.revised_sampling_interval_ms}ms")

queue_size and discard_oldest​

The server MI maintains a queue for each. When the queue is full, data is discarded—and which end of the queue the data is discarded from is determined discard_oldest by:

  • discard_oldest = True (Default) → Discard the oldest, keep the newest
  • discard_oldest = False → Discard the newest, keep the oldest

queue_size = 1 (Default) Retains only the latest value; suitable for "real-time display"; queue_size = N (N > 1) can handle brief publish delays.

Messages are still discarded even when the queue is full

Increase the size queue_size We cannot guarantee that no data will be lost. — It simply delays the "drop" until the moment the queue actually overflows. To ensure absolutely no data is missed, use read(ua.read_history) from the history as a fallback, or adjust the publishing interval so it keeps up with the data rate.

Next Step​