Skip to main content

DataChangeFilter

Overview​

OPC UA Part 4 §7.17 DataChangeFilter: The "trigger / deadband_type / deadband_value" trio.

API​

Type / FunctionCategoryReading and WritingNote
DarraUa_DataChangeFilter (struct)Type—Filter POD
DarraUa_DataChangeFilter_Init(&filter)FunctionWriteFill in the default values (optional)
DarraUa_MonitoredItem_AddWithFilter(sub, node_id, attr, sampling_interval_ms, mode, queue_size, discard_oldest, filter, cb, user_context, out_mi)FunctionWrite"add" with a filter

Filters API in SDK the extension header (not the protocol stack ABI header):

#include <opcua/opcua.h>          /* Subscription Basics ABI */
#include "../include/opcua_filter.h" /* DataChangeFilter / EventFilter / Triggering */
typedef struct {
DarraUa_DataChangeTrigger trigger; // STATUS / STATUS_VALUE / STATUS_VALUE_TIMESTAMP
DarraUa_DeadbandType deadband_type; // NONE / ABSOLUTE / PERCENT
double deadband_value;
} DarraUa_DataChangeFilter;

Related Structures:

typedef enum {
UA_DATA_CHANGE_TRIGGER_STATUS = 0, // Changes StatusCode Only
UA_DATA_CHANGE_TRIGGER_STATUS_VALUE = 1, // StatusCode or Value (default)
UA_DATA_CHANGE_TRIGGER_STATUS_VALUE_TIMESTAMP = 2 // Any change
} DarraUa_DataChangeTrigger;

typedef enum {
UA_DEADBAND_NONE = 0, // No dead zone
UA_DEADBAND_ABSOLUTE = 1, // Absolute Dead Zone
UA_DEADBAND_PERCENT = 2 // Percentage (based on EURange)
} DarraUa_DeadbandType;

Code Example​

#include <opcua/opcua.h>
#include "../include/opcua_filter.h"

DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = "opc.tcp://localhost:4840";
cfg.security_mode = UA_MSG_SECURITY_MODE_NONE;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#None";
cfg.user_token_type = UA_USER_TOKEN_ANONYMOUS;

DarraUa_SessionHandle h = UA_INVALID_SESSION_HANDLE;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);

DarraUa_SubscriptionConfig sc;
DarraUa_SubscriptionConfig_Init(&sc);
sc.publishing_interval_ms = 100.0;
sc.publishing_enabled = 1;

DarraUa_SubscriptionHandle sub = UA_INVALID_SUBSCRIPTION_HANDLE;
DarraUa_Subscription_Create(h, &sc, &sub);

// 1) Absolute Dead Zone 0.5
DarraUa_DataChangeFilter f1 = {
.trigger = UA_DATA_CHANGE_TRIGGER_STATUS_VALUE,
.deadband_type = UA_DEADBAND_ABSOLUTE,
.deadband_value = 0.5,
};
DarraUa_MonitoredItemHandle mi1 = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_MonitoredItem_AddWithFilter(sub, "ns=2;s=Temp", UA_ATTR_VALUE,
100.0, UA_MI_MODE_REPORTING, 1, 1 /*true*/, &f1,
on_change, NULL, &mi1);

// 2) Percentage deadband: 2%
DarraUa_DataChangeFilter f2 = {
.deadband_type = UA_DEADBAND_PERCENT, .deadband_value = 2.0
};
DarraUa_MonitoredItemHandle mi2 = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_MonitoredItem_AddWithFilter(sub, "ns=2;s=Flow", UA_ATTR_VALUE,
100.0, UA_MI_MODE_REPORTING, 1, 1, &f2,
on_change, NULL, &mi2);

// 3) Status Only
DarraUa_DataChangeFilter f3 = { .trigger = UA_DATA_CHANGE_TRIGGER_STATUS };
DarraUa_MonitoredItemHandle mi3 = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_MonitoredItem_AddWithFilter(sub, "ns=2;s=Comm.Status", UA_ATTR_VALUE,
200.0, UA_MI_MODE_REPORTING, 1, 1, &f3,
on_change, NULL, &mi3);

Implementation Notes​

  • Fields are passed by value; perform a deep copy of the necessary fields SDK at the call entry point; after the call returns, the struct can be released or go out of scope.
  • Graceful fallback when Stack does not support custom filters: Still uses the default (no filter) and adds successfully, andGenerate "Warn" logs, Data will be reported in full as usual

Best Practices​

  • For analog values, use "Absolute" as the default, such as 0.5°C
  • Use "Percent" for wide-range signals
  • Digital signals do not require filtering
  • Don't make the dead zone too large; experience: 0.1-2%

Cross-Language Comparison​

C#PythonJavaC++RustC
DataChangeFilterDataChangeFilterDataChangeFilterDataChangeFilterDataChangeFilterDarraUa_DataChangeFilter

Next Step​