
Submission by Dan McGrath. What’s all this about then? Well, I’ve got loads of home automation, and I love it! However, whenever I show it to friends and family, I tend to get one of two responses. The first is that it’s just a gimmick and they’d never want anything like that. The second is that it’s great, but too complicated for them to set up something similar.
Design – Right, so I need something that is cheap, reliable, easy to get hold of. Also something that can be triggered by a simple switch, and that switch could be any of the following:
- Connect it to a socket, light or any other appliance and use it to montor it.
- Attach to a solar panel or LDR to monitor light levels.
- Connect a pair of probes and detect water (plants, rain, leaks etc…)
- Connect to a PIR or Reed switch for security,
- Connect to a smoke alarm for fire protection,
- Connect to a pressure mat etc….
Most people don’t want a pc or server running all day, because of the noise, heat and energy consumption. Simple tiny one board computers can now be bought from $50 each (Xport, Arduino, PicoTux, etc..), but even this seems overkill for what I want…
![]() |
![]() |
![]() |
A managed switch, router, firewall, anything with an ethernet port and some kind of web interface was what I was after, but it had to be cheap… and small…. Then I came up with the idea of a print server… Print servers are ideal, they use very little electricity, are designed to be switched on all the time, can respond to a ping and better still have a in-built webserver too. I did a bit of googling around and saw them for as little as a tenner on ebay. Oh and they are tiny too! I had three ideas for this project:
- The first was that I could break or short the transmit pair on the incoming ethernet cable to the print server. Obviously with these shorted or broken the device would be unable to respond to either a ping or a http request.
I think it would work, but it seemed a bit barbaric, and I’m sure I could do better.
- The second was just to break the power to the device
This had potential from a energy saving point of view as you’d only be powering the device some of the time, of course when it was powered off you wouldn’t see either it’s webpage or a respond to a ping request. I quite liked this idea, the only thing that put me off was that when powered off, it would be impossible to tell if the device was off, or disconnected from the network for another reason – maybe a failure elsewhere. Also I was unsure how long the device would keep the settings (network etc..) while it was off.
What I really wanted was a way of getting a response from the unit to confirm that it was either in one state or another, that way you could be sure of what was really going on. That’s where my third idea comes in.
- The third idea was to fool the print server that a printer was really attached to it,
and then have it so that it appeared that the printer was on or off line.
I did a bit of reasearch, and it appears that pin 13 of the connector is used for this purpose. Take the pin high (i.e apply 5volts to it) and the server thinks that the printer is on_line, take the pin low (i.e remove the voltage)and the server thinks that the printer is off_line.
As all I have to do is apply and remove 5volts, I can just find 5volts somewhere and route it through a switch. Close the switch and it appears that the printer is on_line, open the switch and the printer appears off_line. As I say, this status is reflected in the web interface, so a simple script should be able to poll this page and parse the printer status and then use this information for something useful.
Construction – As mentioned above, I used a Edimax PS-1206P parallel print server, which I bought for about 25 pounds online. It was actually more like 22 quid, but postage and packing bump that up a bit. I ended up buying a handful of these as they were so cheap. I’ve never heard of Edimax before, so the product could be good or bad, but I don’t care, as long as it’ll respond to a HTTP request then I’ll be happy! I was pleasantly surprised when they turned up, they were nicely boxed, and the contents looked ok too:
One thing’s for sure though, this device will never be plugged into the back of a printer. I’ll soon have chopped it up into something far more interesting. Details here: Edimax PS-1206P
Ok, so let’s get the lid off one of these….I just love taking stuff apart, but taking brand new stuff apart is especially fun for me, it just seems so wrong!! There are a couple of phillips head screws on the bottom and once these are removed, the case just pulls apart, although you need to squeeze the sides a bit as the two halves clip into each other.
I was pleasantly surprised with the inside of this unit, it was very well put together. The lord only knows what all the bits are for, I guess there is a processor in there, some memory, a bit of I/O and other stuff I don’t understand.
Now, you could keep the big 36pin centronics socket on the print server and just get hold of the matching plug to connect to it, but these are quite bulky and it seems a bit over the top especially considering we only need to connect to 2 of these 36 pins. I decided to cut the socket off… No, I didn’t do it with an axe, it does look a bit rough at the moment though:

I then desoldered the individual pins from the board and made up a little metal plate to block up the hole left from the missing socket. I drilled a couple of holes in it and connected a pair of screw terminals. A bit of 2 part epoxy and some heatshrink and you have this…

Pretty neat eh?! So that’s the working prototype, with a bit of luck, bridging those two screw terminals will return an on_line status, and leaving them open will give an off_line. So it’s time to test. Note: The pictures above show the connections to pins 35 and 36, this is INCORRECT, subsequent testing showed that I actually needed pins 13 and 19.
I decided to measure the power consumption, and I was pleasantly surprised at what I found, it only uses 6watts, which isn’t very much at all is it? (At 10p per kwh, it’ll cost about 5 quid per year to run)
As I said above, I’m going to poll my server with a HTTP request and collect the printer status, but if you want to just see if it’s there by pinging it, then you can use ping to montior it, using something like:
date
n=1
while [ $n -lt 1000 ]
do
ping -n 1 server_ip
echo $n
let n=n+1
done
date
Shows that this device can easily send (and receive) 1000 pings in 52 seconds which is 20 pings a second. So pinging it is a viable option and should give you a fairly prompt response. Of course if you want to just use ping then you’ll have to either trigger the unit by breaking the power or network connection (it won’t be affected by printer status). Pings don’t really work well on the internet, lots of people and routers disable ICMP requests at their boundaries, however the bonus with this device is that it also has a web interface which can be polled to check its availability. This can be done over the internet easily, and again a short script shows that you can make about 1 request per second using…
#!/usr/bin/bash
user=username
password=password
url=server_url
wget –quiet –http-user=$user –http-password=$password \
–proxy=$proxy $url
grep Off_line printer.htm > /dev/null
if [ “$?” == “0” ]
then echo “Offline”
else echo “Online”
fi
rm printer.htm
Returns a value based on the printer status. Note the webserver onboard is pretty slow, as expected really, but you get a response in less than a second, so I think it’ll be feasable to poll every 5-10secs. Replacing the echo commands with mail or additional wget commands could email you or get a URL (maybe use twitter to SMS you etc..)
Ok, an example of how to update your twitter status is given below:
wget –keep-session-cookies –http-user=username \
–http-password=password –post-data=message \
http://twitter.com/statuses/update.xml
(Replace username, password and message with, well you know..)
Or better still, here’s how to send yourself a tweet when something happens:
wget –keep-session-cookies –http-user=user \
–http-password=password –post-data=message \
http://twitter.com/direct_messages/new.xml
Note, you have to URL encode the message That’s pretty cool isn’t it? See more about the twitter API here. – Twitter API
To see this from the net, you’ll need to NAT to your print server, I’m running a Cisco Router so the following worked for me:
ip nat inside source static tcp extendable
(keep the port number up in the high 50,000s and you’ll get less people scanning and probing you). If you have a Linksys router then the rule will be different, but something like this should do it:
If you haven’t got either of the above, then you are on your own… good luck!
Software – Ok, I gave some examples above, below is a working bash shell script that’ll monitor one of these for you, and twitter SMS you when the state changes. It is a very simple example, but should get you started.
#!/bin/bash
## Web Get Parameters
user=”admin”
password=”1234″
url=”http://ip_address/printer.htm”
## Twitter Parameters
t_user=user
t_passwd=password
## Other Parameters
status=”closed”
while true
do
old_status=$status
wget –quiet –http-user=$user –http-passwd=$password $url
grep Off_line printer.htm > /dev/null
if [ “$?” == “0” ]
then status=”open”
else status=”closed”
fi
rm printer.htm
if [ $status != $old_status ]
then wget –quiet –http-user=$t_user \
–http-passwd=$t_passwd –keep-session-cookies \
–post-data=”user=twitter_username&text=message” \
http://twitter.com/direct_messages/new.xml
fi
sleep 1
done
Alternatively, you could use some monitoring software like the excellent freeNATS to alert you when something happens.
Conclusion – Well, I hope you’ve enjoyed what I’ve done, you have to admit it is home automation
on the cheap, and very easy to do. Cheers – Dan
Useful Links
CPAN – All things Perl
Perl – More things Perl
WGET – WGET application
Edimax – Suppliers of the Print Server Other / Misc
Twitter – Social Networking Site With SMS
This article reproduced from the Original by kind permission of Dan McGrath of yourmissus.com
Want More? – Follow us on Twitter, Like us on Facebook, or subscribe to our RSS feed. You can even get these news stories delivered via email, straight to your inbox every day
Se also : http://tinyurl.com/26blma
Thanks for publishing this its interesting and has generated some good debate
6W seems alot of power to take to detect the state of a device.
Nice job – looks very cool – I might just make one myself – I particularly like the idea of it communicating with Twitter!!!