MikeL's FreeBSD howto - Add a UPS
This is basically a checklist of how to install an Uninteruptable
power supply to be monitored by the system. The intent is not to
cover everything in detail, merely to point you to each of the tasks
that must be performed.
There are several different packages to do this. I tried upsd
(directions below), but it doesn't work with my "dumb" UPS (APC 500).
upsmon actually has some documentation, but it sounds like it
won't either, so I won't even try. The latter mentions
pwrfaild, but I can't find anything about it. Somewhere on the
web I found reference to bkpupsd, so now I'm trying it (many
gory details below).
upsd
- Plug a serial cable from the UPS port to a serial port on your
FreeBSD box. Default is the lowest numbered serial port (probably
labelled "Port 1" on the back of the box).
cd /usr/ports/sysutils/upsd
make
make install
- Goto Autostarting and set up an
autostart script for upsd. This script need not save the pid in
/var/run
, the program does this automatically.
- If necessary, edit /usr/local/etc/upsd.conf. The
default serial port is /dev/cuaa0 (port 1, the lowest
numbered).
- Now you'll get messages on the console that say "Cannot put UPS in
smart mode". I guess this means I should have spent more money on
my UPS. Mine is an APC BackUPS 500. Oh well...
make clean
make deinstall
bkpupsd (Pretty much the same install as upsd)
- Plug in control port.
cd /usr/ports/sysutils/bkpupsd
make
make install
- Goto Autostarting and set up an
autostart script for upsd. This script need not save the pid in
/var/run
, the program does this automatically.
- If desired, edit /usr/local/libexec/bkpups.*. These
scripts are executed by the program when events happen.
- After you've done the install, you can use
man 8 bkpupsd
for more info.
NOTE!
I had to make a special cable to adapt my APC Back-UPS 500 work with
this program. A DB-9 male to female (male is UPS side), with all pins
just passing through, except:
pin 4 is left open on both sides,
and pins 6 and 7 are shorted. The reason is that the UPS is asserting
DTR (pin 4) and DSR. DTR is supposed to be driven by the
computer end, thus it is being held low by the computer. This in
turn, is holding DSR down as well, thus it is left open.
I also had to modify the program -- immediately before the line
ioctl(fd, TIOCMBIS, &dtr_bit);
, I had to
add dtr_bit = -1
; this is the first one
inside the while(1)
loop. Also, the line
else if(lstatus & TIOCM_RNG) {
gets the
TIOCM_RNG
replaced with 0x100
.
Diff listing:
90a91
> dtr_bit = -1;
112c113
> else if(lstatus & 0x100 /*TIOCM_RNG*/) {
---
< else if(lstatus & TIOCM_RNG) {
Protocol notes:
While making the cable work, I had a breakout box plugged into the
serial line. I observed the following:
- The "test" switch causes the same action (as far as the serial
port is concerned) as does pulling the power plug.
- Depressing the "test" switch causes the serial status to change,
and remain in that state as long as the button is held depressed.
When the button is released, the status will return to normal.
- Pulling the power or depressing the test switch with no load on
the UPS (nothing plugged in/turned on), the alarm tone will be
continuous. With a load, the alarm will beep for about 1 second,
about every 4 seconds.
- The UPS asserts DSR and DTR. The UPS also asserts RD. I know,
this is bogus (DTR is DCE, DSR and RD are DCE), but that's the
behaviour I observed from mine.
- DSR tracks DTR. If your computer asserts DTR (as mine does), this
makes it so that no change is observable on DSR either.
- Upon "test" button or powerfail, RD, DSR, and DTR are all forced
low. This means that by monitoring DSR you can test for
powerfail/test-button.
- If your system were to monitor DTR, instead of driving it, you
could monitor DTR to test for powerfail.
- You should also be able to test for powerfail by checking the
recieved data for BREAK (eg. framing error).
- Just for the record, my APC 500 held up my computer (4 SCSI HDs
spun down, full of RAM, Pentium II 266, internal CDROM idle,
nothing else special) for 27 minutes. After that time, the alarm
beep became continuous, and after another about 90 seconds, it
shut off.
- Due to the amount of time it takes to do a battery
charge/discharge cycle, I only did one test for low battery
indication. However, the test was conclusive -- I did not observe
any status change, meaning it is not possible to detect this
status.
Copyright © 1995-2023
Mike Lempriere
(running on host pedicel)