Created
September 4, 2013 17:02
-
-
Save sorz/6439801 to your computer and use it in GitHub Desktop.
Making the LED on router flash with traffic. http://sorz.org/flashled/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#set -x | |
export PATH="/bin:/sbin:/usr/sbin:/usr/bin" | |
IFNAME="eth0" | |
FULLSPEED=1200 # KiB/s | |
LED='/sys/class/leds/tp-link:blue:system/brightness' | |
while [ True ] | |
do | |
# Get traffic data: | |
str=$(ifconfig $IFNAME | grep 'RX bytes') | |
str=${str#*'RX bytes:'} | |
str=${str%' ('*} | |
str=${str%' ('*} | |
now=$((str/1024)) | |
speed=$((now-last)) | |
if [ "$speed" -gt "$FULLSPEED" ] ; then | |
speed="$FULLSPEED" | |
fi | |
last="$now" | |
# Flash LED: | |
ratio=`echo "scale=3;$speed/$FULLSPEED*1000"|bc` | |
ontime=${ratio%'.'*} | |
offtime=$((1000-ontime)) | |
#echo "$ontime" | |
if [ "$ontime" -gt "0" ] ; then | |
echo 255 > "$LED" | |
msleep "$ontime" | |
fi | |
if [ "$offtime" -gt "0" ] ; then | |
echo 0 > "$LED" | |
msleep "$offtime" | |
fi | |
#sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment