Skip to main content

readHistoryEvents

If the server logs event history (HistoryRead Events), the client can retrieve historical events by time range.

Supporting

Signature​

public List<OpcUaEventSubscription.EventArrivedEventArgs> readHistoryEvents(
String nodeId, // Usually i=2253 Server
Instant start,
Instant end,
int maxEvents);

Returns the same type as the EventArrivedEventArgs reused real-time event subscription (field-aligned).

EventArrivedEventArgs Field​

FieldTypeNote
severityint1-1000
messageStringEvent Text
sourceNameStringEvent Source Name
timeFtlongFileTime, 0 = null
eventTypeStringEvent Type NodeId

Usage​

import java.time.Instant;
import java.time.Duration;

List<OpcUaEventSubscription.EventArrivedEventArgs> events = ua.readHistoryEvents(
WellKnownNodes.SERVER,
Instant.now().minus(Duration.ofDays(1)),
Instant.now(),
0);

for (OpcUaEventSubscription.EventArrivedEventArgs e : events) {
long ft = e.timeFt;
Instant t = (ft > 0)
? Instant.ofEpochMilli((ft - 116444736000000000L) / 10000L)
: Instant.now();
System.out.printf("[%d] %s: %s @ %s%n",
e.severity, e.sourceName, e.message, t);
}

Custom EventFilter​

Currently, the default SDK pull includes 4 fields (Severity / Message / SourceName / Time). A builder for complex filtering (by EventType / Severity / SourceNode) will be exposed in a future version API.

Server Requirements​

  • Must support HistoryRead Events (ServerCapabilities flag on the server side)
  • The event source node must have bit 1 of the EventNotifier Attribute (12) set (HistoryRead)

Relationship to Real-Time Event Subscriptions​

APIWhat to bring
subscribeEvents(...)Real-time Events (Occurring During the Subscription Period)
readHistoryEvents(...)Historical Events (Archived on the Server)

Typical setup: readHistoryEvents Run it for 24 hours at startup, then subscribeEvents switch to real-time operation.

Next Step​