Skip to main content

HistoryReadProcessed (C)

HistoryRead Aggregation mode, combined with standard aggregation functions. Given an interval, an aggregation function, and a subinterval width, the server returns the aggregation results for each subinterval.

Preliminary / Supporting
  • To pull all original points, please use ReadRaw.
  • For interpolation at a specific point in time, please use ReadAtTime.

API​

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryReadProcessed(
DarraUa_SessionHandle h,
const char* node_id_str,
DarraUa_DateTime start_time,
DarraUa_DateTime end_time,
double processing_interval_ms,
const char* aggregate_type_node_id,
DarraUa_DataValue*** out_values,
uint32_t* out_count);
ParametersNote
processing_interval_msSubinterval length (milliseconds, > 0)
aggregate_type_node_idStandard Aggregate String NodeId

Return value length = ceil((end - start) / processing_interval), in chronological order.

Standard Aggregation Function NodeId (ns=0)​

NodeIdNameMeaning
i=2342AverageArithmetic Mean
i=11285TimeAverageTime-Weighted Average
i=2348TotalCumulative Total
i=2346MinimumMinimum Value
i=2347MaximumMaximum value
i=2353RangeMax − Min
i=2352CountPoints
i=11427StandardDeviationSampleSample standard deviation
i=11286Deltaend - start difference

For a complete list, see the OPC UA Aggregate Functions Standard (Part 13 §5.4).

Usage​

Hourly average of the 24-hour temperature​

DarraUa_DateTime end   = utc_now_ft();
DarraUa_DateTime start = end - 864000000000LL; /* 24 hours */

DarraUa_DataValue** values = NULL;
uint32_t count = 0;

DarraUa_Status st = DarraUa_Session_HistoryReadProcessed(
h, "ns=2;s=Temperature",
start, end,
/*interval*/ 3600000.0, /* 1 hour */
/*aggregate*/ "i=2342", /* Average */
&values, &count);
/* count ≈ 24; each represents the average for that hour */

for (uint32_t i = 0; i < count; ++i) {
double avg = 0.0;
DarraUa_Variant_GetDouble(DarraUa_DataValue_GetValue(values[i]), &avg);
printf("hour %u avg = %.2f\n", (unsigned)i, avg);
}
DarraUa_DataValueArray_Delete(values, count);

Highest Temperature Each Day of the Week​

DarraUa_Session_HistoryReadProcessed(
h, "ns=2;s=Temperature",
week_ago, today,
/*interval*/ 86400000.0, /* 1 day */
/*aggregate*/ "i=2347", /* Maximum */
&values, &count);

Total traffic in one hour​

DarraUa_Session_HistoryReadProcessed(
h, "ns=2;s=FlowRate",
hour_ago, now,
/*interval*/ 3600000.0,
/*aggregate*/ "i=2348", /* Total */
&values, &count);

Performance Advantages​

  • Aggregation is performed on the server side; the client does not need to first retrieve all the raw data points and then perform the calculations itself.
  • Standard Practices for Cross-Day/Cross-Week Reports

Server Requirements​

  • Historian must implement this aggregate function (the supported functions are listed in the ServerCapabilities/AggregateFunctions column on the server).
  • When aggregation functions are not supported, the status code returned by the server is SDK Pass-through as-is (e.g., BadNotSupported / BadHistoryOperationUnsupported, which is a server-side code; there is no corresponding macro in the client-side header), print it using DarraUa_StatusName and then evaluate it
  • processing_interval_ms If 0 or a negative value is passed,aggregate_type_node_id or if NULL is passed or parsing fails, the client returns immediately UA_STATUS_INVALID_ARGUMENT without sending a request.

Next Step​