Ups control with octoprint


#1

i dont no if this plugin exist, but it would be nice if octoprint could manage an ups to stop in case of power failure
Thanks to help me in mi search


#2

If the brand of the UPS is APC, they usually have some good connectivity to program to.

For example, one could edit the /etc/apcupsd/onbattery script as talked about here to do whatever you need it to do, like gracefully cancel a print job and shutdown the printer after, say, a three-minute sanity check.

One would need a serial-to-USB cable over to the Raspi and the APCUPSD daemon running.


#3

Most modern APC and TrippLite UPS units come with a USB B port and a USB B to USB A cable, so I'm not sure if you need the serial to USB cable these days. Also not sure whether APCUPSD works with the modern ones that use USB, but I'm guessing it does...definitely worth looking at.

I have some of each of the above, and I need to eventually get around to implementing something, though I don't have my printers on UPS units at present and my RPis are hooked up to a UPS that should power them for several hours if there's a power event, so I'd wind up shutting them down by hand (my fiber terminal, router, and switches all have their own UPS units that will power them for at least a few hours). I will likely end up writing something to distribute shutdown instructions over the network to my desktops and servers, though...it's just that power events are rare here (knock on wood).

Needless to say, I'd be interested in hearing if you find that the above works :smiley: Please mark @OutsourcedGuru's answer as the solution if it works for you.


#4

I'm running my printers off some super small APC ES700 but any other fairly modern APC should behave same, they mostly come with "universal port" (looks like ethernet jack) and cable for USB, Serial and few other (RS485 I think) adapters.. Armbian (on opi) recognises it properly:

[  130.258977] usb 4-1: USB disconnect, device number 2
[  162.103823] usb 4-1: new low-speed USB device number 3 using ohci-platform
[  162.396879] usb 4-1: New USB device found, idVendor=051d, idProduct=0002
[  162.396898] usb 4-1: New USB device strings: Mfr=3, Product=1, SerialNumber=2
[  162.396910] usb 4-1: Product: Back-UPS ES 700G FW:871.O2 .I USB FW:O2
[  162.396921] usb 4-1: Manufacturer: APC
[  162.396931] usb 4-1: SerialNumber: xxxxxxx
[  162.733935] hid-generic 0003:051D:0002.0001: hiddev0,hidraw0: USB HID v1.10 Device [APC Back-UPS ES 700G FW:871.O2 .I USB FW:O2                                                                                              ] on usb-1c1b400.usb-1/input0

so it registers as HID device

so one quick root@orangepione:~# apt-get install apcupsd

quick config check and we are ready to go :smiley:

root@orangepione:/etc/apcupsd# apcaccess -h localhost:3551
APC      : 001,034,0829
DATE     : 2018-10-14 02:52:59 +0200
HOSTNAME : orangepione
VERSION  : 3.14.12 (29 March 2014) debian
UPSNAME  : ES700
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2018-10-14 02:52:57 +0200
MODEL    : Back-UPS ES 700G
STATUS   : ONLINE
LINEV    : 236.0 Volts
LOADPCT  : 5.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 18.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Low
LOTRANS  : 180.0 Volts
HITRANS  : 266.0 Volts
ALARMDEL : No alarm
BATTV    : 13.5 Volts
LASTXFER : No transfers since turnon
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
STATFLAG : 0x05000008
SERIALNO : xxx
BATTDATE : 2012-11-20
NOMINV   : 230 Volts
NOMBATTV : 12.0 Volts
FIRMWARE : 871.O2 .I USB FW:O2
END APC  : 2018-10-14 02:53:57 +0200
root@orangepione:/etc/apcupsd#

very small ups as I said, the switch, wifi to eth client, one opi, one camera and one non working printer are loading it already 5% with only 18min of battery time, but, should be more enough to play out whatever is in printer's buffer, save location, move everything to safety and shutdown ...

now all that needs to be developed :smiley: .. I use this ups to battle issues like "need to move the rack with printers and plug it into other socket" so the ups holds the forth till I replug and similar stuff, the printer's are unaware that power was disturbed ... but in theory it should be easy to setup stuff, normally my UPS is not even plugged in as I use OPI boards with single USB so .. it's used by printer :smiley: .. but I do plan to network all the printers in the tower as apcupsd support one device being connected to ups and all devices being notified and being able to query the ups so ... once, if I have a time .. I'll make some plugin if noone makes it in a meantime, major reason I never worked on it is that my main 2 printer's have print plate that goes up/down and that I need power to keep it in place (when power is gone, the plate falls down) so to continue I'd have to rehome, and that's not that repeatable on those 2 printers for XY so I never bothered to try ... also, I'm mostly concerned with 2-3minute power breaks, and the ups solves those with no brains behind it, for long time power outage ... those are sooooooo rare ..


#5

That actually sounds like a fun plugin to work on and I've got an APC Back-UPS ES 650 here under my printer desk. I'm guessing I've got one of those cables around here; the only problem would be where to find it. So it's got an RJ45 data port; check. Probably be easier to build the cable than to find it. <_<

Go ahead and write it. I should be working on other stuff, to be honest.


#6

that RJ45 is where the usb comes from, probbly there's more then just D+ and D- there .. maybe rs232 cou'd not find datasheet for the connector but cable I have works...

I hope someone else will do it, I really hate python :smiley: but if noone does I'll eventually bite the bullet


#7

I actually wrote an APC-to-multiple server shutdown for my datacenter once which included the halon equipment. I just daisy-chained all those together to get that to work. That's why I always buy APC now.


#8

If my plate wasn't full I'd consider putting it together for you, but unfortunately pretty busy lately.