Close

Control

A project log for Modern HP5N

Dragging a mid 90's laser printer, kicking and screaming into the 21st century

timescaleTimescale 11/21/2019 at 13:420 Comments

The core of this project is the ability to reliably turn on and off the printer when there are job in the printer spooler. Seems simple enough. Alas, it is never so! There are many edge cases to factor in and it all depends on how reliable we can get certain data.


In the most simple model, we'd do something like this.

if job {
    waitTime = startupTime + (pages * perPageTime) + cooldownTime
    wait waitTime
    powerDownPrinter
}

But lives never that easy is it? The first problem is that by default, CUPS does not count pages. We have a document size, but that tells precious little about the length of the physical document. It is also uncertain if "lpstat" can be accurately used to determine the state of the job. For instance, what if you print 10 copies of 1 page and CUPS sends off the data with the command, ten times please. The spooler would show no job after the first page came out. And then there are the cases where we have paper jams or ran out of paper. This all has to be tested and considered.

There is a CUPS wrapper called TEA4CUPS which gives much more tools and option which I'm looking at, but for the moment I'd like to keep it simple.

Another option would have been to buy the TP link hs110 version of the "smart" plug. Essentially it is the same as the HS100, but with the added functionality that it can monitor and report on power usage. Depending on how this power data worked, It would be rather simple to monitor the power usage after a job started and only shut the printer off after it returned to "stand-by". Only problem here would be when the printer jams or runs out of paper as it would stop using power and probably hit that low power state.

But for now, we'll just do it the Q&D way. Detect job turn on for 10 minutes and then turn off unless there is still a job in the spooler.

echo "Printer power socket controller 0.1b"
while true; do
        PRINTERSTAT=`lpstat -u`
        if [ -n "$PRINTERSTAT"  ]; then
                echo "Turn On Printer!"
                ./hs100.sh -i 192.168.1.4 on
                sleep 10m
                PRINTERSTAT=`lpstat -u`
                if [ ! -n "$PRINTERSTAT"  ]; then
                        echo "Turn Off Printer"
                        ./hs100.sh -i 192.168.1.4 off
                fi
        fi
        sleep 2

done

Put this in rc.local and we're golden! For now.

Discussions