NAS

Switching power outlets with CUPS/sispmctl

2 1821
tkaiser  
Edited by tkaiser at Wed Nov 26, 2014 05:37

The following is an approach to switch the sockets of USB-connected cheap EnerGenie EG-PM2, EG-PMS, EG-PMS2 socket outlets via CUPS and sispmctl:



The idea behind: Use your ARM board as print server and easily switch on laserprinters when they're needed and switch them off after printing by sending any print job to a special queue that switches the printer's power socket off (don't do that with inkjets or any other device that needs to be turned off safely!)

Here you can find the backend that does the job: http://pastebin.com/S8n7jN2S (read/understand the comments in the script's header carefully. The installation details are outlined there)

Prerequisits (replace "apt-get install" with "yum install" or "pacman -S" when your distro is not Debian based):
  1. apt-get install cups sispmctl
  2. chmod u+s /usr/bin/sispmctl
  3. cupsctl --remote-admin
Copy the Code
Afterwards you can access the CUPS webinterface using https://$IP-ADDRESS-OF-YOUR-BANANA:631/admin/ (you might want to disable remote access afterwards via the web interface itself or by 'cupsctl --no-remote-admin' as root). If there are SiS-PM power outlets connected they will be listed when you access "Add Printer". In my case 2 devices are connected with different serial numbers (01:01:51:45:0b and 01:01:51:23:cb).

Imagine there is a LaserJet HP4500 connected to the fourth socket of the first power outlet then we would need two pseudo printers to switch the printer on and off:







Don't choose a PPD but use 'raw' as printer type, assign any name you want and take care that you enable the 'Share This Printer' checkbox when you want to use this 'pseudo printer' from other machines (this is the real purpose of this whole setup since otherwise you could use sispmctl locally). To create a 'switch the device off' pseudo printer you just choose the right 'device' and then it's exactly the same procedure:



The printer queue names and descriptions do not matter at all since socket and serial number are encoded in the queue's so called 'Device URI' starting with sispmctlcups:// in our case:
  1. root@bananas ~ # lpstat -t
  2. scheduler is running
  3. no system default destination
  4. device for power_off_laserprinter: sispmctlcups://01_01_51_45_0b-4-off
  5. device for switch_on_laserjet: sispmctlcups://01_01_51_45_0b-4-on
  6. device for Switch_Socket_4_on_second_SiS-PM_on: sispmctlcups://01_01_51_23_cb-4-on
  7. ...
Copy the Code


You could not only switch printers on and off using CUPS but other connected devices as well (sounds weird in the first place but the good news is that CUPS supports fine grained authentication for different queues so you can just allow specific machines/users in your network to switch devices connected to the print server). And using eg. Tea4CUPS you could create CUPS queues that consist of two queues: The one that accesses the printer and prints the job and another sispmctl queue that leads automagically to a powered on printer if it was switched off before (you can also use 'prehooks' with Tea4CUPS that switch the printer on prior to printing and then use just a 'switch the printer off when finished' queue to power-off manually over the network).
mega-hz  
Hello,

i made a PI-Printserver using cups and tea4cups and need some help:

tea4cups should turn on a relays before printing to the Laser and turn off the relays after printing with prehook and posthook.
I made two little scripts to switch an gpio and they are working fine.
But i canT get it running with tea4cups.
Maybe i made an error so please help me?

Tis is my printers.conf:


# Printer configuration file for CUPS v1.7.5
# Written by cupsd
# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING
<Printer Canon_iP7200_series>
UUID urn:uuid:821b37ce-6a4f-3c31-6099-a3aec50e5cd7
Info Canon iP7200 series
Location print-server
DeviceURI tea4cups:usb://Canon/iP7200%20series?serial=088A3E
State Idle
StateTime 1501951645
Type 36892
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
</Printer>
<Printer FS-1020D>
UUID urn:uuid:3a66e55b-0c8d-3ac9-7a46-da5672b9dac8
Info Kyocera FS-1020D
Location print-server
DeviceURI tea4cups:usb://Kyocera/FS-1020D?serial=XAX5777229
State Stopped
StateMessage Unplugged or turned off
StateTime 1502138997
Reason paused
Type 4116
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
</Printer>



And this is my tea4cups.conf:


[FS-1020D]
prehook : /home/pi/relays_on.py
posthook : /home/pi/relays_off.py

What is wrong?

Thank you very much for help!

mega-hz  
This works:

[global]
prehook : /home/pi/relays_on.py
posthook : /home/pi/relays_off.py

why not on [FS-1020D] ?

You have to log in before you can reply Login | Sign Up

Points Rules