Official example 05: localagent_threshold — a real TR-181 object
Grow through practice
No need to finish reading — test nowOne line: this is a real TR-181 object, not another toy demo. It uses AMX search paths + expressions to “watch a parameter and fire an event when a condition holds”. Prerequisite: build the AMX base environment first, following “AMX / prplOS development environment”; this article only compiles/runs the example.
What it does
LocalAgent.Threshold.{i}. monitors one parameter:
ReferencePath+ThresholdParam: what to watch;ThresholdOperator+ThresholdValue: the condition (Rise/Fall/Eq/NotEq);- condition true →
Triggeredevent.
ODL: entry
la_threshold.odl:
%config {
import-dbg = true;
rw_data_path = "${prefix}/etc/config";
definition_file = "${name}_definition.odl";
save_file = "${rw_data_path}/${name}/${name}.odl";
defaults_file = "${name}_defaults.odl";
}
import "${name}.so" as "${name}";
include "${definition_file}";
?include "${save_file}":"${defaults_file}";
%define {
entry-point la_threshold.threshold_main;
}
Same shape as before: %config → import → include → ?include → entry-point.
ODL: object tree
%define {
object LocalAgent {
%read-only csv_string SupportedThresholdOperator = "Rise,Fall,Eq,NotEq";
object Threshold[] {
on action validate call threshold_instance_is_valid;
on action destroy call threshold_instance_cleanup;
%unique %key string Alias;
bool Enable = false;
string OperatingMode {
default "Normal";
on action validate call check_enum ["Normal", "Single"];
}
string ReferencePath;
string ThresholdParam;
string ThresholdOperator {
default "Rise";
on action validate call check_is_in "LocalAgent.SupportedThresholdOperator";
}
string ThresholdValue;
event Triggered;
}
}
}
Key points:
Threshold[]: multi-instance;%unique %key Alias: unique key;OperatingMode:Normal/Single(the two modes defined by TR-181);check_is_in "LocalAgent.SupportedThresholdOperator": references another parameter's value as the allowed set (not a hard-coded enum);event Triggered: fires when the condition holds;on action validate/destroy: per-instance validation/cleanup.
ODL: events
%populate {
on event "dm:object-changed" call threshold_changed
filter 'object starts with "LocalAgent.Threshold."';
on event "dm:instance-added" call threshold_added
filter 'object == "LocalAgent.Threshold."';
on event "*" call print_event;
}
- parameter change →
threshold_changed; - new instance →
threshold_added(subscribe the monitor); print_eventfor debugging.
C: implementation
| File | Content |
|---|---|
src/threshold_main.c | entry, stores dm/parser, prints start/stop |
src/dm_threshold_actions.c | _threshold_instance_is_valid / _threshold_instance_cleanup |
src/dm_threshold_events.c | threshold_trigger / threshold_subscribe / _threshold_changed / _threshold_added / _print_event |
It relies on libamxp expressions/search paths (explicitly listed in the README).
Compile / run on the AMX base environment
make
sudo make install
amxrt <install>/etc/amx/la_threshold/la_threshold.odl -o name=la_threshold
Notes:
- the README has typos in paths/arguments (e.g.
la_trheshold); trust the actual install directory; la_threshold_defaults.odlis empty (%populate {}), so there is no default instance; add one with anAliasyourself.
Verification status
- ✅ ODL/source/README: object, key, validate/destroy, events, expression dependency;
- ⚠️ not run locally:
OperatingModetrigger behavior and install path are understood from README/TR-181, not measured; - ❓ to confirm: whether
Singledisables itself after triggering; the recommended way to create an instance when there is no default.
One sentence
It is not “yet another demo”, but a real TR-181 object: search paths + expressions + events. Once you get it, ODL patterns like “dynamic validation/monitoring/triggering” stop being unfamiliar.
Official example: localagent_threshold Related: ODL reference · 05 %config parsing Series: AMX Official Examples.
Comments 0
No comments yet — be the first!