Network printer power-on when needed

My FreeBSD server is now equipped with a TellStick for control of 433.92 Mhz wireless remote switches. Our home is not (yet 🙂 fully controlled by remote switches but we have a few of them now. One of the features I wanted was to control some lights but for some reason the TellStick in the server closet does not reach one of the remote switches so I might get an extender for that later on.

Something that seems to work very well is remote control of a 230V fan (actually an old dual-fan PSU, but it’s a temporary solution) in the server closet. The server closet is next to our bedroom so in order to get rid of some noise at night I now use the TellStick to turn off the fan at 22:00 and start it again at 8:00.

The hack that this blog post is about is meant to power-on my networked HP LaserJet 2200 on demand.  We seldom print everyday so it’s rather pointless to have the printer on all the time. I implemented this solution for fun and I’m not sure that I’m going to keep it.

I thought for a while about how to detect when any computer on the network was trying to print, and I decided to try to listen for ARP who-has requests. This is (almost) the script I use:

#!/bin/sh
/usr/sbin/tcpdump -i em0 -q -l -n arp dst host 172.16.0.96 2>/dev/null |
while read line; do
  /home/david/bin/printer.sh 1 > /dev/null 2>&1
done

As you might deduce from the script it will try to turn on the printer for every ARP request for the printer IP address. This will cause more power-on signals to be sent than necessary, but I call that a feature! 🙂

The printer.sh script looks like this:

#!/bin/sh
`dirname $0`/nexa.sh D 2 $1

And this is the nexa.sh script:

#!/bin/sh
/usr/local/bin/sudo `dirname $0`/rfcmd LIBUSB NEXA $1 $2 $3

Rfcmd is a command line tool for interfacing with the TellStick. I run it as root and I use libusb for the USB support.

A future improvement could be to turn off the printer after it’s been unused for a certain time, but now I simply call printer.sh to turn it off at midnight.

I don’t know if it is bad for the printer to cut the power but it already has a serious smear issue so I’ll only keep it until the toner runs out and then buy a new printer. Brand new networked laser printers with duplex start at €200 here in .se so it shouldn’t be too expensive to get one with good Linux support when the time comes.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.