readHistoryEvents
If the server logs event history (HistoryRead Events), the client can retrieve historical events by time range.
Supporting
- To subscribe to real-time events, please use Event Subscription.
- Please use the following historical variable data: ReadRaw / ReadProcessed.
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
| Field | Type | Note |
|---|---|---|
| severity | int | 1-1000 |
| message | String | Event Text |
| sourceName | String | Event Source Name |
| timeFt | long | FileTime, 0 = null |
| eventType | String | Event 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
| API | What 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.