readHistoryAtTime
Given a set of discrete time points, the server returns the value at that time using the "previous / next / linear interpolation" algorithm. Used for "timeline alignment":
Preliminary / Supporting
- To generate aggregated statistics, please use ReadProcessed.
- To select all origin points in a range, use ReadRaw.
Signature
public List<OpcUaDataValue> readHistoryAtTime(
String nodeId,
List<Instant> times,
boolean useSimpleBounds);
| Parameters | Note |
|---|---|
| nodeId | Objective NodeId |
| times | List of discrete time points (UTC Instant) |
| useSimpleBounds | true = stepped (using the nearest point ≤ t); false = linear interpolation |
Usage
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Collectors;
// Temperatures at every hour on the hour over the past 24 hours
Instant midnight = LocalDate.now(ZoneOffset.UTC)
.atStartOfDay().toInstant(ZoneOffset.UTC);
List<Instant> hours = IntStream.rangeClosed(0, 24)
.mapToObj(h -> midnight.plusSeconds(h * 3600L))
.collect(Collectors.toList());
List<OpcUaDataValue> values = ua.readHistoryAtTime(
"ns=2;s=Temperature", hours, true);
try {
for (int i = 0; i < hours.size(); i++) {
OpcUaDataValue dv = values.get(i);
if (dv != null) {
System.out.println(hours.get(i) + ": " + dv.variant());
}
}
} finally {
for (OpcUaDataValue dv : values) if (dv != null) dv.close();
}
Difference from ReadProcessed
| API | Return |
|---|---|
| ReadAtTime | Each time point corresponds to an interpolated value (not aggregated) |
| ReadProcessed | One aggregate value (Avg / Min / Max / ...) per subinterval |
Example: "Pull data for 24 hours, one value per hour":
- ReadAtTime: Input 25 integer points; return 25 interpolated points (the value at each integer point may be a linear interpolation between adjacent original points)
- ReadProcessed: aggregate=Average, interval=1 h, returns the average of 24 intervals
Use Cases
- Temporal Alignment: Different sensors have different sampling times; they must be synchronized to the same point in time to be compared.
- Database Export: On-the-hour sampling
- Reports: 24 lines per day