Skip to main content

HistoryReadAtTime (C)

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.

API​

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryReadAtTime(
DarraUa_SessionHandle h,
const char* node_id_str,
const DarraUa_DateTime* req_times,
uint32_t time_count,
DarraUa_Boolean use_simple_bounds,
DarraUa_DataValue*** out_values,
uint32_t* out_count);
ParametersNote
req_timesArray of timestamps to query (UTC ticks 100ns)
time_countNumber of timestamps (>0)
use_simple_bounds1 = Use the most recent actual value; 0 = Linear interpolation (must be supported by the server)
out_valuesOutput: DataValue* The array has a one-to-one correspondence with req_times
out_countActual number of rows returned (may be less than time_count)

The return order corresponds req_times one-to-one; the number of responses may be fewer than time_count; when the server has no value for certain timestamps, it will mark them with a status BadNoData code (a server-side code that is passed through SDK as-is; there is no corresponding macro in the client header).

Usage​

#include <opcua/opcua_history.h>
#include <stdio.h>

/* Temperatures at every hour on the hour over the past 24 hours */
DarraUa_DateTime hours[25];
DarraUa_DateTime end_ft = utc_now_ft();
DarraUa_DateTime midnight_ft = end_ft - (end_ft % 864000000000LL); /* A full 24 hours */
for (int i = 0; i < 25; ++i)
hours[i] = midnight_ft + (int64_t)i * 36000000000LL; /* 1 hour */

DarraUa_DataValue** out = NULL;
uint32_t cnt = 0;
DarraUa_Status st = DarraUa_Session_HistoryReadAtTime(
h, "ns=2;s=Temperature",
hours, 25,
/*simple_bounds*/ 1,
&out, &cnt);

if (UA_STATUS_IS_GOOD(st)) {
for (uint32_t i = 0; i < cnt; ++i) {
const DarraUa_Variant* v = DarraUa_DataValue_GetValue(out[i]);
double d = 0.0; DarraUa_Variant_GetDouble(v, &d);
printf("hour %u: %g\n", (unsigned)i, d);
}
}

DarraUa_DataValueArray_Delete(out, cnt);

Difference from ReadProcessed​

APIReturn
ReadAtTimeEach time point corresponds to an interpolated value (not aggregated)
ReadProcessedOne aggregate value (Avg / Min / Max / ...) per subinterval

Example: "Pull data for 24 hours, one value per hour":

  • ReadAtTime: Input 25 integer points; return up to 25 interpolation points (in the same order as the input)
  • 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

Next Step​