Skip to main content

register_nodes / unregister_nodes

register_nodes Register the client's frequently used NodeId with the server; the server returns a temporary, high-performance NodeId (lifetime = Session). Subsequent read/write operations MonitoredItem use this temporary ID directly. How much the temporary ID NodeId saves compared to the original depends on the server implementation; test it on your server to determine.

Determination of Applicability
  • One-time script → Not necessary
  • Long-term operation with high-frequency access to the same node → Highly Recommended
  • Large-scale, continuous SCADA 1000+ Tag monitoring → Must

Signature​

pub fn Session::register_nodes(&self, node_ids: &[&str])
-> Result<Vec<String>, OpcUaError>;

pub fn Session::unregister_nodes(&self, registered_node_ids: &[&str])
-> Result<StatusCode, OpcUaError>;

Usage​

// 1. Register when the app starts
let orig = [
"ns=2;s=Plant.Line1.Sensor.Temperature",
"ns=2;s=Plant.Line1.Sensor.Pressure",
"ns=2;s=Plant.Line1.Sensor.FlowRate",
];
let temp = s.register_nodes(&orig)?;
// "temp" is currently a temporary value provided by the server ID, similar to ["i=99001", "i=99002", "i=99003"].

// 2. Use a temporary one for subsequent frequent visits ID
for _ in 0..10000 {
let dv = s.read(&temp[0])?;
let _ = dv.variant().try_get_f64().unwrap_or(0.0);
}

// 3. Release before the app exits
let temp_refs: Vec<&str> = temp.iter().map(String::as_str).collect();
s.unregister_nodes(&temp_refs)?;

When to Use​

ScenarioNecessity
Single-run script, 100 nodesLow (cost savings are negligible)
Long-term operation, frequent access to the same nodeHigh (significant time savings)
Large-scale SCADA, 1000+ tags, continuous monitoringMust

Performance Data​

The time required for server-side NodeId parsing depends on the implementation; I am SDK not familiar with the server-side parsing algorithm or its complexity:

  • Number NodeId (i=2258) — Determines the parsing overhead and whether register_nodes is worthwhile; this is determined by the server implementation.
  • String NodeId LongPath (ns=2;s=Plant.Line1.Sensor.Temperature) — Same as above; Is the long path slower, How much can register_nodes save? It depends on actual testing on your server.

In Rust, automatic RAII unregistration is a common practice:

use darra_opcua::{Session, OpcUaError};

pub struct RegisteredNodes<'s> {
session: &'s Session,
pub ids: Vec<String>,
}

impl<'s> RegisteredNodes<'s> {
pub fn new(s: &'s Session, originals: &[&str]) -> Result<Self, OpcUaError> {
let ids = s.register_nodes(originals)?;
Ok(Self { session: s, ids })
}
}

impl<'s> Drop for RegisteredNodes<'s> {
fn drop(&mut self) {
let refs: Vec<&str> = self.ids.iter().map(String::as_str).collect();
let _ = self.session.unregister_nodes(&refs);
}
}

// Usage
{
let reg = RegisteredNodes::new(&s, &["ns=2;s=A", "ns=2;s=B"])?;
for _ in 0..1000 {
let _ = s.read(&reg.ids[0])?;
}
} // <- Automatically unregister upon leaving the scope

Error​

ErrorReason
BAD_NODE_ID_UNKNOWNA certain primitive does not exist NodeId (the operation as a whole may still RPC succeed; in this case, the item returns an empty string)
BAD_TOO_MANY_OPERATIONSThe number of registrations in a single request exceeds the server limit (the limit varies by server).
INVALID_ARGUMENTInput containing the character NUL

Note​

  • Registered Temporary ID Valid only for the current session, Becomes invalid after disconnecting
  • Whether the temporary ID remains valid after a session reconnection (transfer_subscriptions) is determined by the server; to be on the safe side, re-register.
  • Temporary IDs that are not released will be released when the session ends, but it is good practice to explicitly unregister them.

Next Step​