Installation and Configuration of a APC UPS using apcupsd
This web-page consists of four sections: Introduction, installation, configuration, and statistics.
1. Introduction
Since one of our machines is configured as print server and because it does other monitoring jobs, I wanted to equip it with an uninterruptable power supply (UPS). Having read already years ago, that there are Linux drivers for UPS's from APC (American Power Conversion) and having seen such a device in an electronics store (Mediamarkt) for Swiss Francs 79.- (about Euro 50.-), I bought the UPS 'APC Back-UPS CS 350 Battery Backup 350'.
2. Installation of Hardware and Software
The installation of the hardware is easy and explained in the manual (and thanks
to the company APC there is a printed manual included, not just a CD, which
needs a Micro$oft program to read it).
Besides the power cables I also connected the data cable, which on one end
(at the UPS) has a RJ-45-like plug and on the other end (at the PC) an
USB plug.
Software installation under Debian (Sarge) Linux with Kernel 2.4.26 is easy
as well:
apt-get install apcupsd (and answer 'Y' when asked during installation)
3. Configuration of apcupsd
Useful information about the configuration of apcupsd can also be found on http://www.apcupsd.com/ (there, click on 'Online Manual')
Should you have a 2.6 Kernel, such as Kernel 2.6.7 as we use it, you should
first do a few steps (if you use a 2.4 kernel, such as kernel 2.4.26, as we did,
skip the following lines):
- Add the following line into your /etc/fstab:
none /sys sysfs defaults 0 0
- Then enter mount /sys
- Make sure, the USB subsystem is there and enter ls -l /sys/bus/usb/drivers
- If 'hiddev' is not there, you have a problem. We had this problem as well
after having upgraded from a 2.4 to a 2.6 kernel and got an error-message
when entering apcaccess. I did two things, which helped to resolve
the problem:
- 1. apt-get remove apcupsd followed by a apt-get install apcupsd
- 2. Plug out and plug in again the USB cable on the PC - then things worked fine again!
We continue the description for 2.4 kernels...
Now, let's check, whether the connected device was detected:
cat /proc/bus/usb/devices reveals (among many other lines):
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 4 Spd=1.5 MxCh= 0 D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 P: Vendor=051d ProdID=0002 Rev= 1.00 S: Manufacturer=American Power Conversion S: Product=Back-UPS 350 FW: 5.4.I USB FW: c1 S: SerialNumber=BB0311000473 C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 30mA I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=00 Prot=00 Driver=(none)Ok, the last line tells us, that there is no driver. We load the driver into the kernel by entering:
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 4 Spd=1.5 MxCh= 0 D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 P: Vendor=051d ProdID=0002 Rev= 1.00 S: Manufacturer=American Power Conversion S: Product=Back-UPS 350 FW: 5.4.I USB FW: c1 S: SerialNumber=BB0311000473 C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 30mA I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=00 Prot=00 Driver=hid(With a 2.6 kernel you will see 'Driver=usbhid' on the line above).
The next step is to create appropriate device files. The installation comes
with a script, which creates these. Simply enter:
/usr/share/doc/apcupsd/examples/make-hiddev
However, trying to start 'apcupsd' by entering the command:
/etc/init.d/apcupsd start
results in a comment like: "Please check your configuration and then remove this warning to make apcupsd work".
In order so follow, what is happening, you should enter (in a separate
window) the command:
tail -f /var/log/apcupsd.events and you may watch what is going on.
So we edit the file /etc/init.d/apcupsd and comment the three lines:
##echo -n "Please check your configuration and then remove this" ##echo " warning to make apcupsd work" ##exit 0After starting acpupsd again, we get the following message:
Mon Oct 04 03:31:50 CEST 2004 apcupsd FATAL ERROR in smartsetup.c at line 177 PANIC! Cannot communicate with UPS via serial port. Please make sure the port specified on the DEVICE directive is correct, and that your cable specification on the UPSCABLE directive is correct. Mon Oct 04 03:31:50 CEST 2004 apcupsd error shutdown completedIt's time to edit the file /etc/apcupsd/apcupsd.conf and there we read, for USB devices we should set the variable DEVICE as follows:
Mon Oct 04 14:48:09 CEST 2004 apcupsd FATAL ERROR in smartsetup.c at line 67 Cannot open UPS port /dev/usb/hiddev[0-15]: No such file or directoryWhy this? A closer look in /usr/share/doc/apcupsd/examples/make-hiddev gives the explanation: the device files are not created under /dev/usb but under /dev/usb/hid! So we again edit /etc/apcupsd/apcupsd.conf and set:
Mon Oct 04 14:50:40 CEST 2004 apcupsd FATAL ERROR in smartsetup.c at line 67 Cannot open UPS port /dev/usb/hid/hiddev[0-15]: No such file or directorySame error again? Mhh... Maybe, we should modify the cable type in the configuration file; so we edit /etc/apcupsd/apcupsd.conf again and set:
Now we see in the file /var/log/apcupsd.events that things finally
work:
Mon Oct 04 15:02:58 CEST 2004 apcupsd 3.10.15 (04 August 2004) debian startup succeeded
The entries in /etc/apcupsd/apcupsd.conf without the commented lines look as
follows:
UPSCABLE smart UPSTYPE usb DEVICE /dev/usb/hid/hiddev[0-15] LOCKFILE /var/lock ONBATTERYDELAY 6 BATTERYLEVEL 5 MINUTES 3 TIMEOUT 0 ANNOY 300 ANNOYDELAY 60 NOLOGON disable KILLDELAY 0 NETSERVER on NISIP 0.0.0.0 NISPORT 3551 EVENTSFILE /var/log/apcupsd.events EVENTSFILEMAX 10 UPSCLASS standalone UPSMODE disable STATTIME 0 STATFILE /var/log/apcupsd.status LOGSTATS off DATATIME 0
4. Statistics of apcupsd
We now may run the command apcaccess and view some statistics and information. Among other lines we get the output:
STATUS : ONLINE BCHARGE : 100.0 Percent TIMELEFT : 43.0 MinutesHowever, the number of TIMELEFT is misleading! Let's now plug off the power to the USV and after a minute or plug it in again. We now obtain:
STATUS : ONBATT BCHARGE : 090.0 Percent TIMELEFT : 11.0 Minuteswhich is more realistic, since we have connected to the UPS not only a PC with a Pentium 4, but also a flat screen, an 8-port switch and an ADSL-router. From now on, the UPS reports the correct values.
TONBATT : 85 seconds (while on battery during this power outage, 0 if online) CUMONBATT: 85 seconds (cumulative time on battery since start of apcupsd)
And, a power failure produces the following entries in the logfile /var/log/apcupsd.events :
Mon Oct 04 15:28:27 CEST 2004 Power failure. Mon Oct 04 15:28:33 CEST 2004 Running on UPS batteries. Mon Oct 04 15:29:58 CEST 2004 Mains returned. No longer on UPS batteries. Mon Oct 04 15:29:58 CEST 2004 Power is back. UPS running on mains. Mon Oct 04 15:29:58 CEST 2004 Power failure. Mon Oct 04 15:29:58 CEST 2004 Power is back. UPS running on mains.The complete output of the command /sbin/apcaccess is given in this BigBrother screen.
After having upgraded to kernel 2.6.8 we experienced the following problem: Entering the command apcaccess (as root) we got the message:
FATAL ERROR in apcaccess.c at line 243 tcp_open: cannot connect to server localhost on port 3551. ERR=Connection refusedThe only thing, which helped, was to unplug the USB-plug at the PC and to plug it in again. Then I entered: /etc/init.d/apcupsd restart
From then on things worked fine again!Last Update: 27Oct2004 uk   -   Created: 04Oct2004
Go to our Linux homepage