read_history_at_time
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
pub fn Session::read_history_at_time(
&self,
node_id: &str,
times: &[SystemTime],
use_simple_bounds: bool,
) -> Result<Vec<DataValue>, OpcUaError>;
| Parameters | Type | Note |
|---|---|---|
| node_id | &str | Objective NodeId |
| times | &[SystemTime] | List of discrete time points (UTC) |
| use_simple_bounds | bool | true = stepped (using the nearest point ≤ t); false = linear interpolation |
Usage
use std::time::{Duration, SystemTime};
// Temperatures at every hour on the hour over the past 24 hours
let now = SystemTime::now();
let times: Vec<SystemTime> = (0..25).map(|h| {
now - Duration::from_secs(((24 - h) * 3600) as u64)
}).collect();
let values = s.read_history_at_time(
"ns=2;s=Temperature",
×,
/*use_simple_bounds*/ true,
)?;
for (t, v) in times.iter().zip(values.iter()) {
println!("{:?}: {:?}", t, v.variant());
}
Difference from ReadProcessed
| API | Return |
|---|---|
| read_history_at_time | Each time point corresponds to an interpolated value (not aggregated) |
| read_history_processed | One aggregate value (Average / Min / Max / ...) per subinterval |
Example: "Pull data for 24 hours, one value per hour":
read_history_at_time: Input 25 integer points; return 25 interpolated points (the value at each integer point may be a linear interpolation between adjacent original points)read_history_processed: aggregate=Average, interval=1 h, returns the average of 24 intervals
"use_simple_bounds" option
true(Default recommendation): Use the most recent actual value ≤ t. If the data is a step wave (PLC boolean/integer state variable), "true" must be used.false: Perform linear interpolation on the server side. The data is continuous analog (temperature / pressure). Recommended: false
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
Error
| StatusCode | Reason |
|---|---|
| BAD_HISTORY_OPERATION_UNSUPPORTED | Not supported on the server side ReadAtTime |
| INVALID_ARGUMENT | node_id contains NUL |
times An empty value is not an error: Returns an empty list (Ok(Vec::new())) directly without making a request.