readHistory (Raw)
public List<OpcUaDataValue> readHistory(
String nodeId,
Instant startTime,
Instant endTime,
int maxValues);
The most commonly used historical read, which returns all raw data points within the specified [startTime, endTime] interval.
Preliminary / Supporting
- Switch to this when there are too many high-frequency data points ReadProcessed Aggregation.
- If you want to include revision history, please use ReadModified.
Parameters
| Parameters | Default | Note |
|---|---|---|
| nodeId | — | Objective NodeId |
| startTime | — | Range starts at (UTC Instant) |
| endTime | — | Range Stop (UTC Instant) |
| maxValues | — | Maximum number of results per query |
Usage
import java.time.Instant;
import java.time.Duration;
import java.util.List;
List<OpcUaDataValue> dvs = ua.readHistory("ns=2;s=Temperature",
Instant.now().minus(Duration.ofHours(1)),
Instant.now(),
1000);
try {
for (OpcUaDataValue dv : dvs) {
long ft = dv.sourceTimestamp();
Instant t = (ft > 0)
? Instant.ofEpochMilli((ft - 116444736000000000L) / 10000L)
: Instant.now();
System.out.println(t + ": " + dv.variant() + " (" + dv.getStatusEnum() + ")");
}
} finally {
for (OpcUaDataValue dv : dvs) if (dv != null) dv.close();
}
Each item must be closed individually.
Memory must be released for each List<OpcUaDataValue> element returned. try-finally: Close each one individually, otherwise there will be a leak.
Exception
| Exception | Meaning |
|---|---|
| OpcUaException(BadHistoryOperationUnsupported) | There is no Historian on the server |
| OpcUaException(BadNotReadable) | The node does not have permission HistoryRead. |
| OpcUaException(BadCommunicationError) | Network Outage |
Performance and Best Practices
- High-frequency data (1000 Hz+) pulled for one day = 86 million+ points → Must use a
maxValueslimit or switch to ReadProcessed Aggregation OpcUaDataValueEach element in the list isAutoCloseable. We recommend using a try-finally block to close them one by one.- All timestamps must be; UTC
Instantdo not use local time.