updateHistory
Write data to the server-side Historian (rather than the "real-time values" from the current read/write operations):
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
public List<Enums.StatusCode> updateHistory(
String nodeId,
HistoryUpdateType updateType,
List<OpcUaDataValue> values);
HistoryUpdateType
| Value | code | Meaning |
|---|---|---|
| HistoryUpdateType.INSERT | 1 | Insert only if the timestamp does not exist |
| HistoryUpdateType.REPLACE | 2 | Replace only if the timestamp exists |
| HistoryUpdateType.UPDATE | 3 | Insert or Replace (whichever applies) |
| HistoryUpdateType.REMOVE | 4 | Delete this timestamp (the SourceTimestamp DataValue for each element in the values array determines which timestamps to delete; the value field is ignored by the server) |
Usage
Backfill Historical Data
import com.darra.opcua.*;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
// OpcUaDataValue Only contains a constructor and no setters — can only be accessed from readHistory / readHistoryModified
// Once the read interface returns an instance, write it back exactly as it is; do not create a record out of thin air on the client side.
//
// Demo: A list OpcUaDataValue obtained readHistory from dvList
List<OpcUaDataValue> dvList = ua.readHistory("ns=2;s=Temperature",
yesterday, today, 100);
try {
List<Enums.StatusCode> results = ua.updateHistory(
"ns=2;s=Temperature", HistoryUpdateType.UPDATE, dvList);
for (int i = 0; i < results.size(); i++) {
System.out.println(" [" + i + "] " + results.get(i));
}
} finally {
for (OpcUaDataValue dv : dvList) if (dv != null) dv.close();
}
Insert only (do not overwrite existing entries)
ua.updateHistory("ns=2;s=Temperature", HistoryUpdateType.INSERT, dvList);
Delete a Single Point (by SourceTimestamp)
ua.updateHistory("ns=2;s=Temperature", HistoryUpdateType.REMOVE, dvList);
// The server only checks each DV SourceTimestamp; once it finds that point, it deletes it.
Permission Requirements
- Node AccessLevel bit 8 (HistoryWrite) must be set
- 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
| Error Code | Meaning |
|---|---|
| BadHistoryOperationUnsupported | This node does not support HistoryUpdate |
| BadUserAccessDenied | No permission |
| BadNotWritable | Node is not writable |
| BadNotSupported | The server is not enabled. HistoryUpdate |
Point-by-point results are based Enums.StatusCode on the value at the corresponding position in the returned list. The specific status codes "Time point already exists" and "Time point does not exist" are not currently provided.