Skip to main content

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​

ParametersDefaultNote
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​

ExceptionMeaning
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 maxValues limit or switch to ReadProcessed Aggregation
  • OpcUaDataValue Each element in the list is AutoCloseable. We recommend using a try-finally block to close them one by one.
  • All timestamps must be; UTC Instant do not use local time.

Next Step​