Skip to main content

Monitoring with Injected NodeId

This tutorial shows you how to dynamically specify which variable to monitor by injecting the NodeId at runtime instead of configuring it statically.

This approach is useful when:

  • The NodeId to monitor is determined by user input or application logic
  • You want to switch between different variables without modifying the flow
  • You're building a flexible monitoring system

Prerequisites

  • An active connection to an OPC UA server (see Create a connection)
  • A subscription configured in the connection endpoint
  • Knowledge of the NodeIds you want to monitor

Configuration

Monitor Node Setup

  1. Start Immediately: Uncheck this option

    When unchecked, the Monitor node waits for the first message containing a NodeId before starting the subscription.

  2. NodeId Field: Leave empty

    The NodeId will come from the injected message instead.

  3. Configure Other Settings:

    • Sample Interval: 1000 ms (or as needed)
    • Queue Size: 1000
    • Discard Oldest: true
Important

You must uncheck "Start Immediately" and leave the NodeId field empty for injection to work.

Inject Node Setup

Configure the Inject node to send the NodeId in its payload:

Option 1: NodeId in topic

{
"topic": "ns=1;s=Temperature"
}

Option 2: NodeId in payload

{
"payload": {
"nodeId": "ns=1;s=Temperature"
}
}

Example Flow - Basic Injection

Here's a simple example with manual injection:

[
{
"id": "inject1",
"type": "inject",
"name": "Monitor Temperature",
"topic": "ns=1;s=Temperature",
},
{
"id": "monitor1",
"type": "OpcUa-Monitor",
"name": "Dynamic Monitor",
"endpoint": "opcua_endpoint1",
"subscription": "subscription1",
"startImmediately": false,
"nodeId": "",
"samplingInterval": 1000
},
{
"id": "debug1",
"type": "debug",
"name": "Show Value"
}
]

How It Works:

  1. Click the Inject node button
  2. The Monitor node receives the NodeId in msg.topic
  3. The subscription starts monitoring ns=1;s=Temperature
  4. Value changes are sent to the output

Tips & Best Practices

NodeId Priority

When both configuration and injection provide a NodeId:

  1. Injected msg.topic takes highest priority
  2. Injected msg.payload.nodeId is next
  3. Configured NodeId is only used if "Start Immediately" is checked

Subscription Lifecycle

  • The subscription starts when the first message arrives
  • Injecting a new NodeId switches the monitored variable
  • The subscription remains active until the flow is stopped
  • OPCUA Server only sends notifications when the value changes. No notifications are sent if the value remains the same.
  • You will always receive notifications only on value changes.

Error Handling

If an invalid NodeId is injected:

  • The Monitor node sends an error message
  • The subscription remains inactive
  • Inject a valid NodeId to retry
// Handle errors in a function node
if (msg.statusCode && msg.statusCode.value !== 0) {
node.error("Invalid NodeId: " + msg.payload);
return null;
}
return msg;

Performance Considerations

  • Frequently changing the monitored NodeId has overhead
  • Each change requires unsubscribing from the old item and subscribing to the new one
  • For monitoring multiple variables, consider monitoring an array instead

Troubleshooting

Monitor Doesn't Start

Symptom: No notifications after injection

Solution:

  1. Verify "Start Immediately" is unchecked
  2. Check that NodeId field is empty
  3. Ensure NodeId is in msg.topic or msg.payload.nodeId or ensure that msg.payload and msg.topic are empty if you want to use the node defined NodeId
  4. Validate the NodeId format and existence using the flask button on a Read node

Static NodeId Ignored

Symptom: Configured NodeId is ignored

Solution:

  • This is expected when "Start Immediately" is unchecked
  • The node waits for injection
  • Check the box to use the static configuration

Next Steps

See Also