PowerKey Pro 600
Volume Number: 13 (1997)
Issue Number: 12
Column Tag: Tools of the Trade
PowerKey Pro 600
by Christopher Hall
This is not your father's powerstrip... A look at the latest in computer automation technology
Figure 1. Sophisticated Cicuits' PowerKey Pro 600.
That Special Morn
It's a special holiday morning and gift wrapping is flurrying as the gadgets and gizmos are ripped open by eager hands. As the children shriek over their eMates and the adults wince at their credit card bills, what should an intrepid Mac System Administrator find as his gift but... a power strip?
"They couldn't get me a tie or cummerbund or something else I don't need? My gift's another power strip?" our heroic Mac loyalist laments ungratefully. With a brave eye, he slowly opens the elegant biodigradable cardboard box to look at Sophisticated Circuits' newest toy, the PowerKey Pro Model 600.
Rummaging thru the box's contents, our Holiday Geek wonders, "Why would a power strip have such a strange ADB cable? And two RJ-11 phone jacks? And software?" Rushing to his Mac, he excitedly installs the software, shuts down, and moves all of his power cords from his brain-dead power strip to the suddenly fascinating PowerKey.
Perhaps this happy scenario will be repeated for many users this year, because the PowerKey Pro 600 is one of the most useful geegaws a Macintosh-using Inspector Gadget could receive. Under the mild-mannered guise of a handsome power strip, the PK Pro 600 hides a powerhouse power controller with all the smarts needed to control its six outlets from your Macintosh by keystroke, schedule, telephone or AppleScript.
What Can It Do - The Basics
As an intelligent power strip, the PowerKey Pro 600 can do simple and useful tasks; even merely starting up the Mac can be enhanced. Older Macs which lack "soft" power (that is, keyboard power on, such as a Power Mac 6100 series lacks), can now enjoy that convenience. Furthermore, if a system has many peripherals to be started up before the CPU (such as hard disks with a lengthy spin up), setting the CPU's outlet with a delay allows true one-touch startup.
Starting up or shutting down on a schedule, as well as saving energy by powering down an idle Mac's monitor, is also easy with the PowerKey's very well-designed software.
Setup and Use
Setting up the PowerKey is a breeze. The hardware requires nary a moment of thought to properly hook ADB, the phone and the power cords together, while the software requires little more than a reboot and some preference setting. Sophisticated Circuits has wisely given a switch for each outlet, the ability to disable the switches and, for the careless scripter who PowerKey's his Mac into not being able to boot, a simple hardware override.
Figure 2. Hardware Setup of the PowerKey Pro.
The PowerKey Editor is the interface to the PowerKey Extension, the background-only application that does the real work. A simple Schedule window shows all the events created for a given PowerKey. Considering that multiple PowerKey Pros can be daisychained over ADB, this control is appreciated for complex power control needs, such as an array of web servers.
Figure 3. The PowerKey Schedule.
Controlling your system by events is quite easy. A PowerKey event consists of a trigger, which can be modified by qualifiers and actions. For example: At 9AM on Mon, Tue, Wed, Thu and Fri, not between Wed, Oct 1, 1997 and Tue, Oct 7, 1997: start up the computer. In other words, it's easy to set up your Mac to boot every weekday, but the week you're away in the Virgin Islands.
Figure 4. The Event Editor.
It is just as easy to create events that toggle any device's outlet, such as your modem or printer.
Event Triggers
The PowerKey has two general types of triggers: time triggers and system triggers. Time triggers are used to create automatic or repeating events while the system triggers actuate on certain types of computer or phone line activity.
Time triggers include: Once Only, Repeating, Days of Week, Day of Month.
System triggers include: "Power On" Key Pressed When Phone rings, Phone Tones Heard, When Hot Key Pressed, When system is Idle, When Power Returns, At Shut Down, When System Crashes, and When Timer Expires.
Figure 5. Triggers.
Event Qualifiers
Qualifiers refine how and when a trigger activates; all of a trigger's qualifiers must be true for the trigger to fire. For example, a When Phone Rings trigger could have qualifiers that allow it to work only after business hours and on weekends. Qualifiers vary depending on the type of trigger, but include: Time Range, Date Range, Days of Week, System Idle, How Started, and System Running.
Event Actions
The PowerKey has a very useful range of actions. In addition to the expected Switch Outlets, Start Up Computer, Shut Down Computer, and Restart, the PowerKey supports Execute Script, Execute QuicKey, Type a Keystroke, Wait, Open File, Quit Application, Mount SCSI Devices, Answer Phone, Add to Log and External Actions.
As an event is constructed, a natural language representation is crafted in the Event Editor Dialog, making the PowerKey one of the simplest-to-use scripting tools available.
Figure 6. Actions Types.
The Not-So-Basics
Remote Control
If that were all the PowerKey could do, it would be useful, but the PowerKey is designed to really shine as true remote control for your system's power. Listening in on the phone line, a PowerKey Pro can do any event based on the phone ringing any number of times, hearing certain touch-tones (DTMF) for security codes, or even distinctive-ring patterns. It was tremendously useful to teach my PowerKey to boot my Mac in any number of different startup configurations. Because an AppleScript (or QuicKey or Frontier script) can be part of an event, altering what software was active at reboot is relatively simple. With a phone call on a distinctive ring (short - long - short) and the entry of a code, my personal Mac can reboot for Apple Remote Access, fax reception, or a quickie web server with never a conflict over which application deserves the serial port. When it's been idle for 20 minutes, the System reboots to the preferred working configuration. As an added bonus, if the Mac was started up or rebooted over the phone, the monitor doesn't need to be powered up, so a nickel's worth of energy is saved.
The only minus with the telephone control is that the PowerKey doesn't understand ISDN lines or PBXes, but that is a small issue; having a dedicated line for computer control can be wise for a mission critical server.
Server Control
No Mac OS server should be without a PowerKey. (Apple, are you listening?) The Server Restart Option, a standard feature of the PK Pro 600 (and an option on the PK Pro 200) is a System Administrator's dream. When a server hangs, the When System Crashes trigger can be set up to restart and make life good again; when the utility company decides to take control of your server's life blood, the When Power Returns trigger can also reset whatever's needed. Many a dollar and much SysAdmin sleep can be saved by this automation. When combined with the secure telephone control of your server, a SysAdmin might actually be able to never touch the server physically except to replace hardware.
Mac-less operation
A Macintosh is needed to program the PowerKeyPro, but a useful feature is that a unit's scheduled events can be programmed at a Macintosh and then placed anywhere. Any Outlet switching action triggered on scheduling or telephone interaction is fully usable.
The User Timer
The PowerKey "pings" the Mac every 10 seconds to determine if the Mac is running; it if fails, the When System Crashes trigger can be fired. Conversely, a mission critical application that must be up and running 24/7, such as a webserver or database, can set the PowerKey User Timer to count down to a restart. As long as the User Timer is reset by the application, the PowerKey serves up power. If the app crashes and cannot reset the User Timer, the PowerKey can restart the Mac and a script or startup alias can have the mission critical application back without a System Administrator's action. Bravo, Sophisticated Circuits. Not only does every Mac OS server need a PowerKey, but every Mac-based info kiosk. (This feature can be implemented without AppleScript by sending an Apple event using Event Class 'PKPr' and Event ID 'Tick'.)
Custom Actions
If the actions the PowerKey Editor offers aren't quite enough, you can write your own External Action. External Actions are nothing more that HyperCard XCMDs. To make the External Action available to the PowerKey software, the compiled XCMD must be placed in a file of type/creator: Xtrn/PKPr and placed in the the PowerKey Folder in the the Preferences folder. After a restart, the new External Action will appear at the bottom of the Action Selector List.
Beeper
A simple PowerKey external, Beeper, plays your beep sound through the Mac's speaker. Beeper takes only one parameter, the number of times to beep the speaker. This code is available on the PowerKey installation disk.
#include<HyperXCmd.h>
#include <string.h>
#include <A4Stuff.h>
static void xcmd_param_to_string
( Handle param, char *str, short max_len );
static long xcmd_param_to_num ( Handle param );
pascal void main ( XCmdPtr pb )
{
// Setup base registers so we can access global variables.
EnterCodeResource();
pb->returnValue = nil; // Setup return value field of pb
if ( pb->paramCount == 0 )
SysBeep( 0L );
else
{
long n, count;
count = xcmd_param_to_num ( pb->params[0] );
for ( n = 1; n <= count; n++ )
SysBeep( 0L );
}
// Restore base registers before we return
ExitCodeResource();
}
static void xcmd_param_to_string
( Handle param, char *str, short max_len )
{
SignedByte state;
if ((param == 0L) || (str == 0L))
return;
state = HGetState (param);
HLock (param);
strncpy (str, *param, max_len);
str [max_len] = '\0';
HSetState (param, state);
return;
}
static long xcmd_param_to_num ( Handle param )
{
long num = 0L;
char temp [256];
char *s;
temp [0] = '\0';
xcmd_param_to_string (param, temp, 255);
s = temp + strspn (temp, " ");
CtoPstr (s);
StringToNum ( (StringPtr)s, &num);
return num;
}
AppleScript and The PowerKey Pro
Although able to run any OSA-compliant script, the PowerKey itself is scriptable, so any event can be scripted and executed. The Core Suite's Standard Events are supported (Get Data, Set Data, Quit Application) as well as PowerKey's own suite.
- execute: execute a specified event
- execute reference
Class application: An application program
- Elements:
- unit by numeric index, by name
- Properties:
- version string [r/o]
- timer integer
- log file specification [r/o]
Class unit: a PowerKey unit
- Plural form:
- units
- Elements:
- outlet by numeric index, by name
- event by numeric index, by name
- Properties:
- name string
- serial number integer [r/o]
Class outlet: an outlet
- Plural form:
- outlets
- Properties:
- name string
- level integer
Class event: an event
- Plural form:
- events
- Properties:
- name string
- serial number integer [r/o]
- owner type class
- enabled boolean
Scripting the PowerKey is simple, whether one uses AppleScript, Frontier, or QuicKeys. A simple (and rather useless) script to flash Outlet # 6 on is
on |pause|(length)
local endTime
set endTime to (current date) + length
repeat while (current date) < endTime
end repeat
end |pause|
on flicker(cycles, delay)
repeat cycles times
tell application "PowerKey Extension"
set level of outlet 6 of unit 1 to 100 - (level of outlet 6 of unit 1)
end tell
|pause|(delay)
end repeat
end flicker
Calling the above script could look like the following:
flicker(4, 1)
Third-Party Integration
The PowerKey has inspired some third party tools and integrates well with others. Acme Technologies offers PowerGate, a CGI (Common Gateway Interface) to the PK Pro, thereby allowing the PK Pro to be controlled securely from the web. Pacific Coast Software also offers a freeware ACGI, SiteMonitor, available at
http://www.pacific-coast.com/st_pages/Product_Dist/sitemcust.html.
Maxum Development's PageSentry is also an excellent fit with a PK Pro. PageSentry checks to see if a web server if up by requesting a page from the server; upon an error, it notifies the administrator. With the addition of a PowerKey Pro 600, PageSentry can merely activate a PowerKey Script to restart the web server. If WebSTAR (or whatever server you use) is set to launch at startup, the web server is back up and serving pages. Notice that this technique requires a Mac to handle the PowerKey, but the web server could be of any flavor: Mac, WinNT, Unix, or BeOS.
Real Uses
The PowerKey has some very special uses. Offering a level of one touch power control and scriptability is a very empowering aid and a blessing for the differently abled. (In fact, it's handy for those of us with more powered peripherals than we might really need.) A PowerKey Pro or three and some diligent scripting can allow the control of almost any electrical thing around someone with limited or nil mobility. Interesting uses can also include turning appliances on and off with your cordless phone, a script, hot key, or even speech recognition, scheduling a computer's startups and shutdown, as well as leaving the monitor off until needed.
Even though I know of no one currently using a PowerKey Pro to do this, having a group of routers controllable via a PowerKey Pro could allow routers to be power cycled so they can properly ping their seed router. The possibilities for creative System Administration abound.
One Year Later
It's a blizzardy New England Sunday afternoon and our snowed-in, yet still intrepid Mac SysAdmin is snug at home surfing the 'Net when the peaceful whine of the monitor's flyback transformer is shattered by a dreaded pager vibrating off the desk. The pager shows an notification from the Southeastern region's sales manager that the Florida sales force's main database is down during the weekend upload of sales figures. Ms. Manager wants it up right away no matter that Mr. SysAdmin's house can't see out of the 8 foot drift and a snowplow is considered a mythical beast.
He calls Ms. Manager and calmly assures her that the database will be up if there is power to the Mac and asks her to call right back if the system isn't up in 5 minutes.
Our System Administrator has little to worry about -- his PowerKey Pro 600 is ready.
When not whipping out articles, Christopher Hall, christopher@macconnect.com, is senior consultant for the chrysalis group/the Software Brewing co. of Memphis, TN and has been consulting since 1985. He is also selling a lovely home in Memphis which would cost $415,000 if it were in California. (3 BR, 2 Bath, pool, ethernet, cheap ISDN, $140K OBO.)