The Planetlabber

0. Table of Contents

3 Philosophical Questions

What am I made of?

How was I made?

How do I communicate?

What do I look like?

Explanation of Planetlabber

1. 3 fundamental Questions

Who am I?

The Planetlabber is a nifty little piece of Hardware that can remotely control the power switch of other PCs.

Why am I?

Because we wanted a way to be able to operate our Planetlab nodes without having to go there, say for example because we happened to put them in the last dark corner of our wine cellar.

What should I do?

Thou shalt listen to our commands on the parallel port and command your slave machines accordingly

2. What am I made of?

To build the Planetlabber you will need the following parts:
Description Jameco Part Number Jameco Price /$ Jameco Link
Connector D-SUB, 25P, M #15114 0.99 link
Prototype Builder, 1.6"x2.7" #105099 5.25 link
Case, ABS Speedy, 3.125"x2.875" #18921 3.15 link
Power Supply TRANS,WALL,REG,9VDC/250MA F2 #190529CJ 7.15 link
You will need on set of the following for each Node controlled
@TRANSISTOR,PN2222A,NPN,SIL,GP,TO-92(10),40Vceo,100@.15A #178511 0.129 link
@ RESISTOR,1/4W 5%,2.0K OHM, #30277 Bag of 100@0.99 link
Relay, DIP, SPST, 5VDC, 1A Cont #106462 2.15 link


3. How was I made?

The circuit layout is very easy and looks like this:

circuit layout

As you can see it is in fact so easy that it is possible to put multiple triggers in series on the same platine. Our example uses 3.
It uses a DC power source which can be anywhere between 9 and 20V. Which makes it possible to power it with a simple 9V battery or the 12V line of a Molex Connector.
We added a LED for easier debugging but that is not entirely neccesary since most people will use it in a closed box anyway. The wire to the parralel port can be connected to any of the 8 Data Ports. The pinout of the female side looks like this:

You might want to skip the first Data Port D0, because in our tests it seems that most PCs set it to high on startup.

4. How do I communicate?

Following standard linux practice we use a very small setuid c-Program to write to the DATA Port and a shell script to wrap everything else.
The C program looks like this:

Code Listing 4.1: Setuid C-Program "ParPort.c"

#include <stdio.h>

int main(int argc, char **argv){
	
	int fd = fopen("/dev/port",2);
	fseek(fd,0x378,0);
	fwrite(fd,1,1,&argc[1]);
}

Code Listing 4.2: compile and set setuid 'root' of "ParPort.c"

$ gcc -o ParPort ParPort.c
$ chown root ParPort
$ chmod +s ParPort  

The shell script looks like this:

Code Listing 4.3: Shell script "Planetlabber.sh"

#! /bin/bash
# script to trigger the 'Planetlabber'
# makes use of ParPort.c 

# --var section-- #
#short timeout (for on)
SHORT_TO=1
#long timeout (for off)
LONG_TO=4
#set number of remote triggers here
NUM=3
#set offset=1 if you skipped the first data-line
OFS=0
# ---end var section--- #

#set the mask to appropiate dec. value
MASK=$(echo "(2^$NUM)-1" | bc)

#and now set the byte to the ones we actually want to trigger if given
arg2=$2

#second arg zero || greater 8 => set to 255
[[ -z "$arg2" || "$arg2" > 8 ]] && arg2=255

#second arg < 9 => shift bit into right place
[[ "$arg2" < 9 ]] && arg2=$((1<<($arg2-1)))

#apply mask and shift with offset
BYTE=$(( (arg2&MASK) << OFS ))

#function that handles both starting and stopping with diff. TO
starp() {
		#pull down all the bits first
		./ParPort 0
		#then set them
		./ParPort $BYTE
		#wait a while
		sleep $1
		#and pull down again
		./ParPort 0
}

case "$1" in
	start)
		starp $SHORT_TO ;;
		
	stop)
		starp $LONG_TO ;;
		
	"" | restart)
		starp $LONG_TO ;;
		starp $SHORT_TO ;;
	
	*) echo "Usage: ${0##*/} [start|stop|restart] [<num>]"; exit $E_PARAM;;
			# everything else. 
		
esac

Code Listing 4.4: Save and make Planetlabber.sh executable as follows:

$ chmod +x Planetlabber.sh

Of course it is entirely possible to program that behaviour with only a c-Program or only a shell script, which would make use of dd:

Code Listing 4.5: Using dd to write 0x1 to par1

echo -e '\001' | dd seek=888 of=/dev/port ibs=1 obs=1 count=1

Now all you have to do is call that script with the node-number that you wish to start or stop.
If you do not supply a node number, all nodes will be affected.
If you do not supply an action restart is the default.
Now, say you think thats all very nice, but what if I want to be able to do all that with my web browser? You could just come up with a little php script, that will wrap all that nicely in a lot of clicky-coulory buttons (which we will, for the sake of simplicity, omit here):

Code Listing 4.6: Planetlabber.php

<html>
<head>

</html>
</head>

5. What do I look like?