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
-
Start Immediately: Uncheck this option
When unchecked, the Monitor node waits for the first message containing a NodeId before starting the subscription.
-
NodeId Field: Leave empty
The NodeId will come from the injected message instead.
-
Configure Other Settings:
- Sample Interval:
1000ms (or as needed) - Queue Size:
1000 - Discard Oldest:
true
- Sample Interval:
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:
- Click the Inject node button
- The Monitor node receives the NodeId in
msg.topic - The subscription starts monitoring
ns=1;s=Temperature - Value changes are sent to the output
Tips & Best Practices
NodeId Priority
When both configuration and injection provide a NodeId:
- Injected
msg.topictakes highest priority - Injected
msg.payload.nodeIdis next - 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:
- Verify "Start Immediately" is unchecked
- Check that NodeId field is empty
- Ensure NodeId is in
msg.topicormsg.payload.nodeIdor ensure that msg.payload and msg.topic are empty if you want to use the node defined NodeId - 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
- Monitor Multiple Variables - Monitor multiple variables at once
- Monitor JSON Structure - Use structured data for monitoring
- Deadband Filtering - Reduce notification frequency