Skip to main content

RegisterNodes / UnregisterNodes (C)

RegisterNodes The service registers NodeId the client's frequently used values on the server, and the server returns a temporary NumericNodeId (lifetime = Session). Subsequent Read/Write operations use this temporary ID directly MonitoredItem. The amount of savings NodeId achieved by using the temporary ID compared to the original values depends on the server implementation; please test this based on your server's actual performance.

Determination of Applicability
  • One-time script → Not necessary
  • Long-term operation with high-frequency access to the same node → Recommendations
  • Continuous Monitoring of a Large Number of Tags → Recommendations

API​

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_RegisterNodes(
DarraUa_SessionHandle h,
const char* const* node_ids_to_register,
uint32_t count,
char*** out_registered_node_ids);

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_UnregisterNodes(
DarraUa_SessionHandle h,
const char* const* registered_node_ids,
uint32_t count);

out_registered_node_ids Points to an array char** where each element is a temporary string NodeId provided by the server. Free them DarraUa_Free one by one, then free the array DarraUa_Free itself.

Complete Usage​

#include <opcua/opcua.h>
#include <stdio.h>

int main(void)
{
/* ... Assuming a connection has been established ... */
DarraUa_SessionHandle h = /* ... */;

/* 1. Register when the app starts */
const char* orig[] = {
"ns=2;s=Plant.Line1.Sensor.Temperature",
"ns=2;s=Plant.Line1.Sensor.Pressure",
"ns=2;s=Plant.Line1.Sensor.FlowRate",
};
uint32_t count = 3;

char** registered = NULL;
DarraUa_Status st = DarraUa_Session_RegisterNodes(h, orig, count, &registered);
if (!UA_STATUS_IS_GOOD(st) || !registered) {
fprintf(stderr, "RegisterNodes failed: %s\n", DarraUa_StatusName(st));
return -1;
}

for (uint32_t i = 0; i < count; ++i)
printf("%s -> %s\n", orig[i], registered[i] ? registered[i] : "(null)");

/* 2. Use a temporary one for subsequent frequent visits ID */
for (int j = 0; j < 10000; ++j) {
DarraUa_Status rs = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, registered[0], UA_ATTR_VALUE, &rs);
if (dv) DarraUa_DataValue_Delete(dv);
}

/* 3. Release resources before the app exits — First, unregister the server handle */
DarraUa_Session_UnregisterNodes(
h, (const char* const*)registered, count);

/* 4. Free the local string array */
for (uint32_t i = 0; i < count; ++i)
if (registered[i]) DarraUa_Free(registered[i]);
DarraUa_Free(registered);

return 0;
}

When to Use​

ScenarioNecessity
One-time script; exits after a single runLow (cost savings are negligible)
Long-term operation, frequent access to the same nodeHigh
Continuous Monitoring of a Large Number of TagsHigh

Performance​

After registration, the server returns a NumericNodeId, which is used directly MonitoredItem for subsequent Read and Write operations.

The extent of the benefit depends on the server-side implementation, SDK No promises regarding the gear ratio; Please test this on your own server before deciding whether to implement registration.

Note​

  • Registered Temporary ID Lifecycle = Session, Becomes invalid after disconnecting; must be re-registered
  • Before the app closes, it should UnregisterNodes proactively release the server's registration entries.
  • The memory for the temporary ID string is allocated by stack malloc; it must be freed DarraUa_Free using free, not the standard free. free

Next Step​