Quantcast
Channel: Linux Device Hacking
Viewing all articles
Browse latest Browse all 46958

LEDs on GoFlex Net

$
0
0
I've just completed my project to get my GoFlex Net running Debian using davygravy's rootfs (thank you davygravy, it's a neat rootfs that's reliable and works well). I will post about my experiences and things I learnt later.

I wanted to get some visual feedback from the device and the 8 big LEDs on the GoFlex Net were not doing anything so why not. Looking around at what others had done, it's relatively simple to control the leds with the trigger file.

There's a Linux utility called iostat, that gives most of the data needed to control the LEDs. I've set this up so that it gets new results every 1 second, and just the latest update. I've then piped into an awk script that figures out whether lights needs to be on or off. CPU I've used the idle percentage and subtracted from 100% to give CPU usage. I've used the "timer" trigger for sda/sdb and the standard "default-on" for the RAID array (I'm booting SATA off of sda1).

Also awk has to be "forced" to update with the "interactive" flag and the fflush command, otherwise any output just gets buffered and this doesn't work.

Anyway, this is what I came up with, mine I've put into the /etc/rc.local file :

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# For LED control on Seagate GoFlex Net that's been Debianised
# (c) Don Charisma 2013

iostat -z 1 | awk -W interactive '
BEGIN { sda="none";
		sda_prev="none";
		sdb="none";
		sdb_prev="none";
		md1="none";
		md1_prev="none";
		cpu20="none";
		cpu20_prev="none";
		cpu40="none";
		cpu40_prev="none";
		cpu60="none";
		cpu60_prev="none";
		cpu80="none";
		cpu80_prev="none";
		cpu_utilise=0
	  }
# if hard drives or RAID active, set flag for LED
/sda/ {	sda="timer"; }
/sdb/ {	sdb="timer"; }
/md1/ { md1="default-on"; }
# Find the line with CPU info, pick the last number = percentage idle
# subtract it from 100 to give CPU utilisation
/\..*\..*\..*\..*\..*\..*/  { cpu_utilise = 100 - $6;
				if (cpu_utilise >= 20.0) { cpu20="default-on"; }
				if (cpu_utilise >= 40.0) { cpu40="default-on"; }
				if (cpu_utilise >= 60.0) { cpu60="default-on"; }
				if (cpu_utilise >= 80.0) { cpu80="default-on"; }
				}
/Device:/ { if (sda != sda_prev)
				{ print sda > "/sys/class/leds/status:white:left0/trigger";
			      fflush( "/sys/class/leds/status:white:left0/trigger" ); 
				}
				
			if (sdb != sdb_prev)
				{ print sdb > "/sys/class/leds/status:white:left1/trigger"; 
				  fflush( "/sys/class/leds/status:white:left1/trigger" ); 
				}
			
			if (md1 != md1_prev)
				{ print md1 > "/sys/class/leds/status:white:left2/trigger"; 
				  fflush( "/sys/class/leds/status:white:left2/trigger" );
				  print md1 > "/sys/class/leds/status:white:left3/trigger"; 
				  fflush( "/sys/class/leds/status:white:left3/trigger" ); 
								  
				}
			if (cpu20 != cpu20_prev)
				{ print cpu20 > "/sys/class/leds/status:white:right0/trigger"; 
				  fflush( "/sys/class/leds/status:white:right0/trigger" ); 
				}
				
			if (cpu40 != cpu40_prev)
				{ print cpu40 > "/sys/class/leds/status:white:right1/trigger"; 
				  fflush( "/sys/class/leds/status:white:right1/trigger" ); 
				}

			if (cpu60 != cpu60_prev)
				{ print cpu60 > "/sys/class/leds/status:white:right2/trigger"; 
				  fflush( "/sys/class/leds/status:white:right2/trigger" ); 
				}				

			if (cpu80 != cpu80_prev)
				{ print cpu80 > "/sys/class/leds/status:white:right3/trigger"; 
				  fflush( "/sys/class/leds/status:white:right3/trigger" ); 
				}	
				
			sda_prev=sda;
			sda="none";
			sdb_prev=sdb;
			sdb="none";
			md1_prev=md1;
			md1="none";
			cpu20_prev=cpu20;
			cpu20="none";
			cpu40_prev=cpu40;
			cpu40="none";
			cpu60_prev=cpu60;
			cpu60="none";
			cpu80_prev=cpu80;
			cpu80="none";

}
END { print "The end"; }
' &

exit 0

Prior to using the script you'll need to install iostat:

# for iostat
apt-get install sysstat

Obviously it's possible to use the LEDs differently with different triggers, this is just what suited me best. Here's a picture of how the LEDs will work http://doncharisma.org/?attachment_id=805

I think the LEDs need kernel support, this has been tested with davygravy's 3.3.2 kernel from his post about the NSA320.

I wasn't able to get any LED working with network traffic. The posts that I read involved using iptables, but I don't think the davygravy 3.3.2 kernel is setup for this. Anyone have another way of doing it ?

As mentioned earlier I will document the entire procedure of getting this working with RAID1 and OpenMediaVault, on my blog http://DonCharisma.org when I've finished writing it up and here too.

Cheers,

Don Charisma

Viewing all articles
Browse latest Browse all 46958

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>