ea65e840c05dc7e8c8d7e9af9053c37e16c8f9b6
[blog.git] / _posts / 2009-08-29-printer_power.markdown
1 ---
2 layout: post
3 title: Printer, power
4 date: '2009-08-29 22:30:25 +0000'
5 mt_id: 289
6 blog_id: 1
7 post_id: 289
8 basename: printer_power
9 categories:
10 - tech
11 ---
12 My printer is a nice Kyocera FS1800 laser thingie, connected via an USB<->parallel port adapter. It works nicely, is fast enough but up to now had one annoying edge: I had to turn it on when I wanted to print something, and later remember to turn it off. As I don't print much, keeping it on all the time would be a pure waste, but I regularly forgot to turn it off.
13
14 Now, I do own two ["SISPM"](http://www.gembird.de/produkte/produkt_details.php?phg=2&pug=1&id=765) devices for some time already, just never got them setup. After all you have to uncable everything to get them in, brrr. Back when I changed my [desktop hardware](http://blog.ganneff.de/blog/2009/08/04/new-hardware.html) I used one of the two devices already, so whenever I suspend my desktop it also turns off both monitors and an external usb hub, automagically getting them back on as soon as I resume. Nice little thing.
15
16 Today I took the time to install the second SISPM. This time connected to my soekris net5501 box, so the cups on it can turn the printer on whenever I want to print. Getting this integrated into cups was a small challenge, but not that hard to solve. And it should be easily adaptable to similar devices, as long as you have a linux binary to control it...
17
18 - First you need a cups backend script. I based mine on some I found via google. That one didn't work at all, but gave me the right hints. The script is <form mt:asset-id="44" class="mt-enclosure mt-enclosure-file" style="display: inline;"><a href="http://blog.ganneff.de/blog/blog/sispm">available here.</a></form>
19
20 - Place it into */usr/lib/cups/backend/*
21
22 - Reconfigure your cups to use the new sispm backend for your printer instead of whatever you had before. Make your life easy, note down the old DeviceURI, you need it. The new DeviceURI will simply be the old one, prepended by "sispm:PORT", where you replace port by the number of the power plug you connected your printer to.
23
24 - I use a second script to turn the printer off, which runs every 5 minutes from cron. The script checks if the last print attempt was done more than ten minutes in the past and only then turns power off. You can <form mt:asset-id="45" class="mt-enclosure mt-enclosure-file" style="display: inline;"><a href="http://blog.ganneff.de/blog/blog/printeroff">get the script here.</a></form>
25
26 - Run this script every 5 minutes from cron. A file with a line like the following should do.
27 <pre>
28 */5 * * * * root if [ -f /var/run/cups/sispm/jobdone ]; then /usr/local/bin/printeroff >/dev/null ; fi
29 </pre>
30
31 - Enable the user lp to turn power on, by adding a line like below to your sudoers. Replace 1 by the number of the outlet you want to control. You do not need the right to turn power off, as that script runs as root.
32 <pre>
33 lp ALL=(root) NOPASSWD: /usr/bin/sispmctl -o 1
34 </pre>
35
36 - Create */var/run/cups/sispm/* and make sure the user lp can write to it.
37
38 You are done, cups should now turn on power for your printer whenever you want to print, and it should magically go off 10 minutes later.