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);
| Parameters | Note |
|---|---|
| processing_interval_ms | Subinterval length (milliseconds, > 0) |
| aggregate_type_node_id | Standard Aggregate String NodeId |
Return value length = ceil((end - start) / processing_interval), in chronological order.
Standard Aggregation Function NodeId (ns=0)
| NodeId | Name | Meaning |
|---|---|---|
| i=2342 | Average | Arithmetic Mean |
| i=11285 | TimeAverage | Time-Weighted Average |
| i=2348 | Total | Cumulative Total |
| i=2346 | Minimum | Minimum Value |
| i=2347 | Maximum | Maximum value |
| i=2353 | Range | Max − Min |
| i=2352 | Count | Points |
| i=11427 | StandardDeviationSample | Sample standard deviation |
| i=11286 | Delta | end - 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 usingDarraUa_StatusNameand then evaluate it processing_interval_msIf 0 or a negative value is passed,aggregate_type_node_idor if NULL is passed or parsing fails, the client returns immediatelyUA_STATUS_INVALID_ARGUMENTwithout sending a request.