Monitoring a Single Variable
This tutorial shows you how to monitor a single OPC UA variable and receive notifications whenever its value changes.
The Monitor Node subscribes to data changes on the OPC UA server. Unlike the Read Node which retrieves values on demand, the Monitor Node continuously listens for changes and sends notifications automatically.
Prerequisites
- An active connection to an OPC UA server (see Create a connection)
- A subscription configured in the connection endpoint
- The NodeId of the variable you want to monitor
Configuration
Name
Specify a descriptive name for the node to identify it in your flow.
Endpoint
Select the predefined endpoint of the OPC UA server. The endpoint must have at least one subscription configured.
Subscription
Choose the subscription to use for monitoring. The subscription defines:
- Publishing Interval: How often the server sends batches of notifications
- Lifetime: How long the subscription remains active without activity
- Max Notifications: Maximum number of notifications per publish cycle
A single subscription can handle multiple monitored items efficiently.
Start Immediately
When checked, the node begins monitoring as soon as the flow starts, using the NodeId specified in the configuration.
Leave this checked for simple scenarios where you monitor a fixed variable.
NodeId
Specify the NodeId or browse path of the variable to monitor. Supported formats:
Direct NodeId:
ns=1;s=Temperature
Browse Path:
/2:MyDevice/1:MyTemperatureSensor/2:ParameterSet/3:Temperature
Verified Browse Path:
[/2:MyDevice/1:MyTemperatureSensor/2:ParameterSet/3:Temperature](ns=1;s=Temperature)
Use the flask button to verify your NodeId or the ... button to browse the server's address space.
Sample Interval
The interval (in milliseconds) at which the OPC UA server samples the variable for changes. Default: 1000 ms
The server samples the value at this rate and compares it to the previous value. Notifications are only sent when an actual change is detected.
According to OPC UA Specification Part 4, the server only sends notifications when the data value actually changes.
Example values:
1000- Sample every second500- Sample twice per second100- Sample 10 times per second0- Use the server's minimum sampling interval
Queue Size
The maximum number of notifications to store in the queue. Default: 1000
If the client cannot process notifications fast enough, they accumulate in this queue. When full, the behavior depends on the "Discard Oldest" setting.
Discard Oldest
When the queue is full:
- Checked (default): Oldest notifications are removed to make room for new ones
- Unchecked: Newest notifications are discarded
Keep the default (checked) to ensure you always receive the most recent values.
Example Flow
Here's a basic example to monitor a temperature sensor:
[
{
"id": "monitor1",
"type": "OpcUa-Monitor",
"name": "Monitor Temperature",
"endpoint": "opcua_endpoint1",
"subscription": "subscription1",
"startImmediately": true,
"nodeId": "ns=1;s=Temperature",
"samplingInterval": 1000,
"queueSize": 10,
"discardOldest": true
},
{
"id": "debug1",
"type": "debug",
"name": "Show Temperature"
}
]
Flow Setup:
- Add Monitor Node: Drag the
OpcUa-Monitornode to your flow - Configure Endpoint: Select your OPC UA server endpoint
- Select Subscription: Choose an existing subscription
- Set NodeId: Enter
ns=1;s=Temperature(adjust to your server) - Configure Sampling: Set sample interval to
1000ms - Enable Start Immediately: Check the box
- Deploy: Deploy your flow
Expected Output
The Monitor node sends a message each time the temperature changes:
{
"topic": "ns=1;s=Temperature",
"payload": 23.5,
"statusCode": {
"value": 0,
"description": "Good"
},
"sourceTimestamp": "2024-11-24T10:30:45.123Z",
"serverTimestamp": "2024-11-24T10:30:45.125Z"
}
Message Properties:
payload: The current value (23.5°C in this example)statusCode: Quality of the data (Good, Bad, Uncertain)sourceTimestamp: When the device measured the valueserverTimestamp: When the server received the value
Output Formats
You can control the output format using msg.outputType:
Value Format (Default)
Only the value is returned in the payload:
{
"payload": 23.5
}
DataValue Format
Complete OPC UA DataValue with all metadata:
{
"payload": {
"value": 23.5,
"statusCode": {
"value": 0,
"description": "Good"
},
"sourceTimestamp": "2024-11-24T10:30:45.123Z",
"serverTimestamp": "2024-11-24T10:30:45.125Z",
"sourcePicoseconds": 0,
"serverPicoseconds": 0
}
}
Tips & Best Practices
Initial Value Notification
You'll always receive an initial notification when monitoring starts, even if the value hasn't changed. This confirms the subscription is active.
Efficient Sampling
- Set
samplingIntervalto match your application's needs - Don't sample faster than necessary (wastes server resources)
- Use
0to let the server choose the optimal interval
Queue Management
- For critical data: Use large queue size with "Discard Oldest" enabled
- For real-time data: Use small queue size to avoid stale values
- Monitor
msg.sequenceNumberto detect missed notifications
Connection Management
The Monitor node automatically:
- Reconnects if the connection is lost
- Re-establishes subscriptions
- Resumes monitoring without manual intervention
Troubleshooting
No Notifications Received
- Check Connection: Verify the endpoint is connected (green dot)
- Verify NodeId: Use the flask button to validate the NodeId
- Check Subscription: Ensure the subscription is active
- Review Status: Look for error messages in the debug panel
Too Many Notifications
- Increase the
samplingIntervalto reduce sampling frequency - Implement deadband filtering (see Deadband Filtering)
- Use queue size to buffer bursts
Missing Notifications
- Increase
queueSizeto buffer more notifications - Check if "Discard Oldest" is appropriately set
- Verify network stability
Next Steps
- Monitor Multiple Variables - Monitor multiple variables simultaneously
- Monitor JSON Structure - Monitor complex data structures
- Monitor Subtree - Monitor an entire branch of the address space
- Deadband Filtering - Filter notifications based on value changes