Skip to main content

UpdateHistory

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

High-Sensitivity Operations

HistoryUpdate: These are disabled by default on most production servers and must be explicitly enabled by an administrator, along with compliance auditing. See the server requirements for details.

Signature​

std::vector<Status> UpdateHistory(
std::string const& node_id,
HistoryUpdateType update_type,
std::vector<DataValue> const& values);

HistoryUpdateType​

The enumeration is defined in darra/opcua/history.hpp:

enum class HistoryUpdateType : int32_t {
Insert = 1, // Insert a new value; if it already exists, the operation fails.
Replace = 2, // Replace if it already exists; otherwise, the operation fails.
Update = 3, // "Insert" or "Replace"—either works
Remove = 4, // Delete by time; use only the `values` array field SourceTimestamp ; ignore the `value` field
};

Note: in Remove mode, within the values array each DataValue's SourceTimestamp determines which points to delete; the value field is ignored by the server.

Usage​

Backfill Historical Data​

// DataValue Can only be constructed using a resource handle (explicit DataValue(DarraUa_DataValue*, bool owns)),
// There is currently no high-level entry point that constructs values directly.
std::vector<DataValue> dvs;
// ... Preparing DVS

auto results = s.UpdateHistory("ns=2;s=Temperature",
HistoryUpdateType::Update, dvs);

for (size_t i = 0; i < results.size(); ++i) {
std::cout << "values[" << i << "] status = 0x"
<< std::hex << static_cast<uint32_t>(results[i]) << "\n";
}

Insert only (do not overwrite existing entries)​

auto results = s.UpdateHistory("ns=2;s=Temperature",
HistoryUpdateType::Insert, dvs);

Delete at a Specified Time​

// Use the `Remove` type to DataValue determine SourceTimestamp which node to delete.
auto results = s.UpdateHistory("ns=2;s=Temperature",
HistoryUpdateType::Remove, dvs_with_timestamps);

Permission Requirements​

  • The node must have write access to History (AccessLevel)
  • Users must have HistoryUpdate permissions
  • This feature is disabled by default on most production servers and must be explicitly enabled by an administrator.

Error Code​

UpdateHistory There are two types of failures, each requiring a different approach:

① Total failure — Abort darra::opcua::Exception; do not return a value

Trigger Conditionsex.status()
values[i] The handle is nullStatus::DarraInvalidArgument
RPC / Transmission failed (HistoryUpdateData returned a value other than "Good")Raw code returned by the server

② Failure by item — Listed item std::vector<Status> by item in the return value, in the same values order as

StatusMeaning
Status::BadHistoryOperationUnsupportedThis node does not support HistoryUpdate
Status::BadUserAccessDeniedNo permission
Status::BadNotWritableThe server refused the write operation (specific reasons, such as the timestamp already existing or not existing, are determined by the server).

No exceptions were thrown overall.is not equal to"Written successfully" for each entry — the returned list must be checked item by item.

Next Step​