Skip to main content

HistoryUpdate (C)

Write data to the server-side Historian (rather than the "real-time values" from the current read/write operation):

High-Sensitivity Operations

Writing to the history will modify archived data. Whether this is allowed is determined by server-side policies and the permissions of the account making the call; the server may deny the request outright.

API​

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryUpdateData(
DarraUa_SessionHandle h,
const char* node_id_str,
int32_t update_type,
const DarraUa_DataValue* const* values,
uint32_t count,
DarraUa_Status* out_results); /* The caller allocates count */

update_type enumeration​

ValueMeaning
1Insert (Insert a new value; fails if the value already exists)
2Replace (Replace if it exists; fail if it doesn't exist)
3Update (Insert or Replace—either is fine)
4Remove (Delete by time; the values array uses only the SourceTimestamp field; the value field is ignored)

out_results[i] Receives the corresponding write DataValue status; may be NULL to indicate that it is ignored (the top-level return value still represents the service-level status).

Usage​

Call Patterns​

#include <opcua/opcua_history.h>

/* Prepare 3 historical data points */
DarraUa_DataValue* dvs[3];
for (int i = 0; i < 3; ++i) {
dvs[i] = DarraUa_DataValue_New();
/* The currently public C header provides only a DataValue read interface.
(GetStatus / GetServerTimestamp / GetSourceTimestamp / GetValue),
None SetValue / SetStatus; Assembly DataValue capabilities for writing are not currently available */
}

DarraUa_Status results[3] = { 0 };
DarraUa_Status st = DarraUa_Session_HistoryUpdateData(
h, "ns=2;s=Temperature",
/*update_type*/ 3 /* Update */,
(const DarraUa_DataValue* const*)dvs,
3,
results);

for (int i = 0; i < 3; ++i)
printf("point %d: %s\n", i, DarraUa_StatusName(results[i]));

for (int i = 0; i < 3; ++i)
DarraUa_DataValue_Delete(dvs[i]);

Insert only (do not overwrite existing entries)​

DarraUa_Session_HistoryUpdateData(
h, "ns=2;s=Temperature",
/*update_type*/ 1 /* Insert */,
(const DarraUa_DataValue* const*)dvs, 3, NULL);

Permission Requirements​

  • Node AccessLevel must contain HistoryWrite bits (0x08)
  • The calling account must have the necessary permissions HistoryUpdate; if permissions are lacking, the server returns a rejection status code.

Error Code​

Top-level return value = server HistoryUpdateResult.statusCode Pass-through as-is (Errors such as "not supported," "no permission," or "not writable" are returned by the server.) Errors generated by the client stack itself are handled using the following predefined macros:

Error CodeMeaning
UA_STATUS_GOODSuccess
UA_STATUS_INVALID_HANDLEInvalid session handle
UA_STATUS_INVALID_ARGUMENTInvalid parameter (update_type outside the range 1–4, count equal to 0, values equal to NULL, or contains a NULL value; NodeId parsing failed)
UA_STATUS_BAD_SERVER_NOT_CONNECTEDSession Not Connected
UA_STATUS_BAD_TIMEOUTSingle-use RPC Timeout
UA_STATUS_BAD_ENCODING_ERROR / UA_STATUS_BAD_DECODING_ERROREncoding/decoding failed

Common server rejection codes (UA_STATUS_BAD_USER_ACCESS_DENIED/ UA_STATUS_BAD_NOT_WRITABLE / UA_STATUS_BAD_SERVICE_UNSUPPORTED etc.) are also passed through as-is. out_results[i] 's one-way status codes are returned by the server as-is; there is no guarantee that they correspond to macros defined by the client. When printing, use DarraUa_StatusName to interpret them.If an Insert operation encounters an existing historical data point, or if a Replace or Remove operation encounters a nonexistent historical data point, the server will return the appropriate rejection status code.

Historical Notes​

Not available at this time.

Next Step​