birds like wires

Search

iPhone 4: Pffft.

iPhone 4

To say that I ‘caved’ would be to presume that I was holding out against the mighty onslaught of iPhone 4 propaganda, information, misinformation, excitement and mighty tech goodness. Unfortunately, the outcome was inevitable.

Matters were made worse by the fact that I had just registered a shiny new credit card, supposedly destined to help with the fact I’m lacking a kitchen, when the email exclaiming “pre-order!” hit my inbox. Higher cashback in the first 3 months. Access around the traffic jam through the Apple Store for Education. The excuse that “I’ve never had a new iPhone before”. Oh, hell.

So nine days later I was taking a couple of snaps of the box, holding the latest piece of Apple tech in my hand, and generally being bowled over by the whole thing. This was punctuated by the hacking of my 17-year-old SIM card into a new, svelte shape using a Stanley knife and a small fight with iTunes and some distant, tired servers. Voilá˝°! Factory unlocked goodness.

Rubbish

Here’s the tricky bit. What to say about it? After a couple of weeks surely everyone has had their say already? Camera? Check. It’s great, and there’s a flash. And there are two of them. And they both do video. Sleek new look? Check. It’s built like the proverbial outhouse, looks great, weighs a bit more. Awesome screen? Check. It’s awesome.

Keep reading...

Security, Energy and Home Automation

http://www.flickr.com/photos/bjdawes/3475478301/

Everybody loves a bit of home automation, don’t they? Traditionally, geeks such as myself would be toying around with X10 modules, which provide a mature platform for automating pretty much anything in your home. But if X10 isn’t your thing, there may be an alternative.

Here’s my admission. I never figured X10 out. If I’d bought a few modules and started playing I’d probably have got a lot further, but I always held back because of the price of the modules and the fact that I already use powerline communication for ethernet, and didn’t really like the idea of putting more interference into my mains supply.

Alarming

Not long after we moved into our house, we realised that the burglar alarm was useless. The charging circuit was completely burned out, the battery was leaking, the control panel was a squashed mess (mostly the four keys that made up the code) and nobody ever pays any attention to a burglar alarm going off, other than to get grumpy about the noise. I looked at a number of alternatives, including some very interesting units with GSM modules that could send and receive text messages. But they were super-expensive and required an approved installer with the proprietary programming app on their laptop. The pennies and the ethos didn’t add up for me, and the wall controllers were ugly.

Then, one morning, I was listening to Digital Planet and heard Bill Thompson discussing a system called AlertMe that they’d been testing. Back in those days it was purely a security system with ambition, but it sounded good and the website contained the magical letters: API. Oh, and the magical word: discount. :)

Keep reading...

Mac OS X Energy Scripting

http://www.flickr.com/photos/dan_h/416023415/

We’ve got a variety of Macs running OS X versions 10.4, 10.5 and 10.6. They’re all managed from an Xserve with MCX preferences through Workgroup Manager, but for some reason I’ve just never managed to get them all to settle nicely with their power management settings.

While it’s lovely to have the control of these things through Workgroup Manager, I finally got miffed with it not working, particularly with the Tiger clients. It’s also not good to have rooms of machines burning away power and their components pointlessly.

Terminal

So I did what I usually do. Write a script. There’s an excellent blog called Managing OS X which had already covered this issue, so using GregN’s script as inspiration I came up with this in perl.

  1 #!/usr/bin/perl -w
  2 
  3 #powerman.pl v1.01 (23/03/10)
  4 # Installed in /usr/local/bin
  5 
  6 # Makes sure basic power management settings are maintained, and
  7 # power down machines when we can get away with it.
  8 
  9 use strict;
 10 
 11 my $clires;
 12 my $logfile = '/var/log/powerman.log';
 13 my $lockfile = '/tmp/powermanpmsetdone';
 14 
 15 # Log housekeeping (erase log if >100KB).
 16 $clires = `touch $logfile`;
 17 my $logsize = -s $logfile;
 18 if ($logsize > 102400) {
 19 	$clires = `echo > $logfile`;
 20 }
 21 
 22 # Let us alter the power management settings if we force it.
 23 if ("@ARGV" =~ 'force') {
 24 	$clires = `rm $lockfile 2>/dev/null`;
 25 }
 26 
 27 # Figure out where we are.
 28 my $hostname = `hostname`;
 29 
 30 # Discover system version.
 31 my $osxver = `sw_vers`;
 32 if ($osxver =~ "10.6") {
 33 	$osxver = "6"
 34 } elsif ($osxver =~ "10.5") {
 35 	$osxver = "5"
 36 } elsif ($osxver =~ "10.4") {
 37 	$osxver = "4"
 38 }
 39 
 40 
 41 # Set some basics, unless we've already done so recently.
 42 if (! -e $lockfile) {
 43 
 44 	my $pmbasics = `pmset -a hibernatemode 0 halfdim 1 womp 1 sleep 0 powerbutton 0 disksleep 30 autorestart 1 displaysleep 9 repeat wakeorpoweron MTWRF 08:45:00`;
 45 	$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: UPDATE: General power management settings have been updated." >> $logfile`;
 46 
 47 	if ($osxver >= 5) {
 48 		my $pmleo = `pmset -a ttyskeepawake 1`;
 49 		$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: UPDATE: Power management settings for Mac OS X 10.5 and later have been updated." >> $logfile`;
 50 	}
 51 	
 52 	if ($hostname !~ 'cluster') {
 53 		my $pmleo = `pmset -a displaysleep 20`;
 54 		$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: UPDATE: Power management settings for studio (non-cluster) machines have been updated." >> $logfile`;
 55 	}
 56 
 57 }
 58 
 59 
 60 # Now we get active with some potential shutdowns.
 61 my $currenthour = `/bin/date +%H`; chomp $currenthour;
 62 my $idletime;
 63 my $consoleuser;
 64 my $ttysuser;
 65 my $sysload;
 66 
 67 # How long have we been idle?
 68 my @idle = `/usr/sbin/ioreg -c IOHIDSystem`;
 69 foreach (@idle) {
 70 	if (/Idle/) {
 71 		my @idlevalue = split /= /, $_;		
 72 		$idletime = int((pop @idlevalue)/1000000000);
 73 		last;
 74 	}
 75 }
 76 
 77 # Is anybody using the console?
 78 my @console = `/usr/bin/who`;
 79 foreach (@console) {
 80 	if (/console/) {
 81 		$consoleuser = 1;
 82 	}
 83 	if (/ttys/) {
 84 		$ttysuser = 1;
 85 	}
 86 }
 87 
 88 # Are we madly processing away on something?
 89 my @uptime = `uptime`;
 90 foreach (@uptime) {
 91 	my @load = split / /, $_;
 92 	$sysload = int((pop @load));
 93 	last;
 94 }
 95 
 96 # Things to do if we're outside our usual hours (0800-2100).
 97 if (($currenthour < 8) || ($currenthour > 20)) {
 98 	
 99 	$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: snore: powerman.pl starting an out-of-hours check..." >> $logfile`;
100 	
101 	# If there's no console user, nobody on a terminal session, the system has been idle 20 mins and there's not much activity, shut down.
102 	if (($idletime > 1200) && ($consoleuser < 1) && ($ttysuser < 1) && ($sysload <= 2)) {
103 		
104 		if ($hostname =~ "cluster") {
105 			$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: SHUTDOWN: Shutting down the system due to lack of activity out-of-hours." >> $logfile`;
106 			my $shutdown = `/sbin/shutdown -h now`;
107 		} else {
108 			$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: If this had been a cluster machine, it would have been shut down due to lack of out-of-hours activity." >> $logfile`;
109 		}
110 			
111 	}
112 	
113 	# If there IS a console user, but they've been inactive for an hour and there's barely a hint of processor usage, shut down.
114 	if (($idletime > 3600) && ($consoleuser == 1) && ($ttysuser < 1) && ($sysload <= 1)) {
115 		
116 		if ($hostname =~ "cluster") {
117 			$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: SHUTDOWN: Forcing an out-of-hours shutdown with an inactive console user present." >> $logfile`;
118 			my $shutdown = `/sbin/shutdown -h now`;
119 		} else {
120 			$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: If this had been a cluster machine, we would have forced an out-of-hours shutdown with an inactive console user present." >> $logfile`;
121 		}
122 			
123 	}
124 	
125 } else {
126 	
127 	$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: heartbeat: powerman.pl just completed an in-hours check." >> $logfile`;
128 
129 }
130 
131 if (! -e $lockfile) {
132 
133 	$clires = `echo "\`date  +'%Y-%m-%d %H:%M:%S'\`: heartbeat: powerman.pl successfully completed it's first run for this boot." >> $logfile`;
134 	$clires = `touch $lockfile`;
135 
136 }

powerman.pl [4.10KB] (92)

The idea is that this runs via launchd however often you would like. Using Lingon to create a .plist file, I have it triggered every hour. It uses the hostname of the machine to determine where it is, with different rules applied if the system is a ‘cluster’ or a ‘studio’ machine. Once per boot it reapplies the power management policy, and on every run it examines the state of the machine and decides whether it should be powered down.

Keep reading...