← All posts

LED management in prplOS: TR-181 Device.LEDs and tr181-led

Grow through practice

No need to finish reading — test now

One line: an LED is not a few GPIOs; it is a remotely manageable TR-181 object tree. tr181-led hides the /sys/class/leds details behind Device.LEDs.

Component and version

  • Component: prpl-foundation/components/core/plugins/tr181-led
  • Current main: 97ae806 (2026-09-23, defaults: preserve sysfs LED state at startup)
  • Latest release in the changelog: v0.8.3 (2024-08-19)
  • License: BSD-2-Clause-Patent

It is not OpenWrt's leds script; it is a TR-181 data model + AMX plugin.

Data model: Device.LEDs

odl/tr181-led_mapping.odl has one key mapping:

%config {
    %global "proxy-object.'Device.LEDs.'" = "LEDs.";
}

The plugin uses the short LEDs. path internally and exposes the standard Device.LEDs. path on the bus / to remote management.

Device.LEDs has three main parts:

  • BrightnessLimiter: global brightness cap, 0..100;
  • LED[]: one instance per LED;
  • CycleElement[]: the lighting sequence for each LED.

Key LED.{i} parameters:

ParameterPurpose
Aliasunique key, write-once
Enablepower this LED on/off
Namesysfs LED name (unique)
StatusDisabled / InUse / Controlled / Error
Reasontextual purpose, e.g. “Broadband Down”
CyclePeriodRepetitionsremaining cycles; -1 = infinite
Location / RelativeX/YPositionpanel position
MaxBrightnessfrom hardware/driver
CycleElementNumberOfEntriesnumber of lighting steps

A CycleElement describes “how to light for a period”:

  • Order: sequence;
  • Color: RGB hex, e.g. FF0088;
  • Brightness: percentage, -1 means unchanged;
  • Duration: duration in ms;
  • FadeInterval: transition time from the previous step in ms.

The full cycle length is the sum of all Duration values.

Why not just write sysfs

Carrier CPE needs LEDs that are remotely manageable, descriptive, and composable:

  • multi-color: one RGB LED, or red/green/blue monochrome LEDs overlaid;
  • blink/pulse: frequency, duty cycle and intensity are configurable;
  • state: Disabled, InUse, Controlled, Error;
  • remote management: TR-181 paths can be driven by ACS/USP/Web UI.

tr181-led provides that abstraction while still writing sysfs underneath.

Implementation: four key files

src/led_main.c

  • stores dm/parser/default_led_path;
  • led_init maps an LED instance to sysfs devices;
  • led_deinit_all / take_led manage the controlled state;
  • one LED can map to multiple underlying LEDs (color overlay).

src/led_device.c

  • hex_to_rgb parses colors;
  • led_sysfs_write calls mod-led-common's led-sysfs-write via amxm_execute_function;
  • led_set_mode writes trigger / mode;
  • led_set_fade uses timer + delay_on / delay_off (half each);
  • led_validate_colors / led_apply_colors handle a single LED or R/G/B overlay.

src/led_cycle.c

led_valid_state requires all of:

Status == "InUse"
CyclePeriodRepetitions != 0
CycleElementNumberOfEntries != 0
at least one CycleElement.Enable == true
LED.Enable == true

Then element_start_next advances with a timer:

  • find the next enabled CycleElement;
  • update CurrentCycleElement.CycleElementReference in a transaction;
  • apply color/brightness/fade;
  • decrement CyclePeriodRepetitions when > 0;
  • if state is invalid, stop the timer and set brightness to 0.

mod-led-common

The module that actually writes sysfs. Plugin config:

so-dir = "/usr/lib/amx/tr181-led/modules"
so-name = "mod-led-common"
mod-name = "common-behavior"

So tr181-led does not open() sysfs directly; it goes through an AMX module, which is easier to reuse and test.

Permissions: why CAP_DAC_OVERRIDE

The documentation states the plugin runs as tr181_app and keeps only CAP_DAC_OVERRIDE, because it must write /sys/class/leds.

This is the usual trade-off for user-space hardware management:

  • not root;
  • still able to bypass sysfs file permissions;
  • ACL files (acl/) control who may change LEDs over the bus.

Design analysis

What is good

  • Declarative effects: Order/Duration/Color/Brightness/FadeInterval instead of hard-coded blinking in C;
  • Multi-color abstraction: single LED or R/G/B overlay;
  • Hardware limits: MaxBrightness from the driver, BrightnessLimiter as a global cap;
  • Readable state: Status + CurrentCycleElement tell remote management what is active;
  • Persistence: %persistent + ODL storage, restored after reboot.

Cost and boundaries

  • sysfs dependency: LED names, trigger, delay_on/off, max_brightness depend on kernel/driver;
  • user-space timers: each cycle step uses amxp_timer; jitter is worse than a hardware blink engine;
  • color overlay sync: the doc requires the low-level driver to synchronize overlays; user space can only approximate;
  • Controlled semantics: hardware-controlled LEDs are not monitorable and should have no CycleElement entries;
  • incomplete documentation: led_main_documentation.md has many empty sections; Suspend/ULED[] depend on the actual ODL/version (⚠️).

Difference from OpenWrt

A common OpenWrt approach is:

/sys/class/leds + procd/rc.local + scripts

tr181-led is:

Device.LEDs (TR-181) → AMX data model → mod-led-common → sysfs

The former is simpler and fine for home routers; the latter adds a model but gains remote management, uniform semantics, and multi-color/effect descriptions.

Docker virtual-node test

tr181-led ships mock LEDs (test/common/mock_leds), so no real /sys/class/leds is needed.

On top of amx-base, add libamxm / libsahtrace, then run the upstream unit tests:

docker build -f examples/led/Dockerfile -t amx-led-test .
docker run --rm amx-led-test

Measured result:

  • 4 test suites / 14 tests / 0 failures
  • valgrind: 0 errors
  • covers sysfs device lookup, brightness/color/fade, cycle state machine, module loading and start/stop

This is a unit-test virtual node, not a full prplOS node: no ubus/procd, real driver, or remote-management path.

Repo: amx-greeter-demo/examples/led.

Verification status (site mission)

  • ✅ source/docs: component path, commit, ODL, mapping, led_main/device/cycle;
  • ✅ semantics: Device.LEDs mapping, CycleElement, led_valid_state, CAP_DAC_OVERRIDE are backed by source/docs;
  • ✅ Docker virtual node: upstream 4 suites / 14 tests on mock LEDs, 0 failures;
  • ⚠️ not a full prplOS run: no ubus/procd, real driver, or remote-management path;
  • ❓ to confirm: Suspend/ULED[] version differences and per-driver fade/pulse capabilities.

One sentence

tr181-led turns LEDs from “sysfs knobs” into a “TR-181 object tree”: remotely manageable, descriptive, multi-color; the cost is permissions, timers and hardware differences.


Source: tr181-led (97ae806) Virtual-node test: amx-greeter-demo/examples/led Related: prplOS vs OpenWrt · From UCI to a data model · AMXRT is a runtime Series: prplOS Official Code Walkthrough & Testing.

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.