Network Activity LED with Linux LED Subsystem

This is a nice userspace application I use on my router to control the Internet connection status LED in “smart” way.

The idea is simple, instead of just randomly blink the LED when there is some activity on the network, this application checks for the total bytes transferred on the network interface, and blinks the LED every 100KB of data.

That behavior is borrowed from modern electric counter, which have a LED that blinks every predefined number of Watt/hour.

That’s useful because you can quickly have an idea of the bandwidth utilization of your connection by just checking how often the LED blinks, so you can instantly identify a low-bandwidth constant traffic by a high-bandwidth traffic.

Operation

All the configuration is done in #defines at the beginning of the source. This is not so elegant but simplifies the whole thing.

When started, the application open the LED_FILE path, which have to be set to the “brightness” file of the LED to be used. After that, the application daemonize, and start checking the combined traffic on the interface “ppp0” every 100ms.

From this moment, every time the total traffic grow up to the configured RATE, the led is blinked for 100ms.

That’s it!

Start and Stop

To make some sense, the application have to be started when the PPP connection is established and killed when the connection goes down.

Also, the status LED should be normally ON when the connection is up, and goes OFF when the connection is terminated.