23.02.2023 8:52

I needed to make a LED blink on network activity on an embedded Linux device. In modern Linux kernels drivers can control LEDs directly through the LED trigger mechanism. Unfortunately many network drivers don't implement this, or only implement link up/down not link activity triggers. On embedded systems you're often even locked into some magical patched kernel provided by the system vendor, so it might be tricky to install a kernel-space solution like OpenWRT's ledtrig-netdev. Hence the proper way of implementing this was out of reach for me. To get this functionality I created net-led-blinker, a daemon that does a similar thing in user-space, at the cost of a tiny bit of extra CPU time.

When I was looking for existing solutions, I found PiLEDlights, a collection of daemons by Ragnar Jensen. These daemons are made for Raspberry Pi and, among other things, can blink a LED on network activity. Since Jansen's code uses a Raspberry Pi specific way of accessing a LED it was not directly usable for me, but I took the source as a base to create my own daemon.

I modified the code so that it accesses the LED through the user-space LED trigger mechanism. This means that the new daemon is pretty much platform-independent, but has two requirements:

  • The LED on the system must be accessible through /sys/class/leds file system. You can't just use any GPIO, although a GPIO on the system can usually be defined as a LED though the device tree without recompiling the kernel if you have gpio-leds available.

  • The kernel must be compiled with the one-shot LED trigger. This frees a few cycles in the user-space daemon, since it only needs to wake once per period (not twice - you turn the LED on and the kernel turns it off by itself). It also provides a nice mechanism for setting on and off time through the /sys filesystem for creating different blinking patterns.

Ragnar's code detects network activity on all interfaces on the system. A single LED is used to show network activity on any of them. This is another benefit of net-led-blinker over the existing kernel solutions I'm aware of. Triggering a LED from a network driver or ledtrig-neddev means that you need a separate LED for each network interface.

I packaged the net-led-blinker daemon in a Debian package for easy installation. The package includes systemd configuration that runs net-led-blinker on boot and reads configuration from /etc/default.

net-led-blinker is available from my git repository with the following command:

git clone

Consult the included README for building and usage instructions.

I retained the original Unlicense that was used by Ragnar in their project, so the code is pretty much unencumbered with licensing terms.

Posted by Tomaž | Categories: Code

Add a new comment

(No HTML tags allowed. Separate paragraphs with a blank line.)