What is this?
Raspberry Pi OS (Raspbian) install apcupsd Installation guide
What is apcupsd?
apcupsd is a open source UPS mangement and controlling software, it allows the computer to interact with APC UPSes.
First, install apcupsd utility, and the dynamic web page monitor.
sudo apt-get -y install apcupsd apcupsd-cgi
Then backup the configuration file.
sudo cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.orig
sudo cd /etc/apcupsd/
Using vim editor to editing the configuration file.
sudo vim apcupsd.conf
If you are using APC BN650M1 series, and connect to raspberry by USB cable, the configuration file will be like this:
## apcupsd.conf v1.1 ##
UPSNAME BN650M1-TW
# UPSCABLE <cable>
UPSCABLE usb
# UPSTYPE
UPSTYPE usb
DEVICE
# POLLTIME <int>
#POLLTIME 60
# LOCKFILE <path to lockfile>
LOCKFILE /var/lock
# SCRIPTDIR <path to script directory>
SCRIPTDIR /etc/apcupsd
# PWRFAILDIR <path to powerfail directory>
PWRFAILDIR /etc/apcupsd
# NOLOGINDIR <path to nologin directory>
NOLOGINDIR /etc
# During power failures
ONBATTERYDELAY 6
BATTERYLEVEL 15
MINUTES 10
TIMEOUT 0
ANNOY 60
ANNOYDELAY 60
# NOLOGON <string> [ disable | timeout | percent | minutes | always ]
NOLOGON disable
# KILLDELAY <seconds> 0 disables
KILLDELAY 0
# Network Information Server
# NETSERVER [ on | off ] on enables, off disables the network
NETSERVER on
# NISIP <dotted notation ip address>
NISIP 0.0.0.0
# NISPORT <port> IANA
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
# Configuration statements used if sharing
# UPSCLASS
UPSCLASS standalone
# UPSMODE
UPSMODE disable
After saving the configuration file, start (or restart) apcupsd service.
sudo service apcupsd start
Running commond, if everything goes right, you will saw the UPS status.
apcaccess
If you want to monitoring your UPS online (via LAN network), please follow the instructions below.
Install Apache 2.4.
sudo apt-get -y install apache2
Then backup the configuration file.
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.orig
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.orig
Using vim editor to editing the apache configuration file.
sudo cd /etc/apache2/
sudo vim apache2.conf
The configuration file section at Directory will be like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
# apcupsd
ScriptAlias /apcupsd/ /usr/lib/cgi-bin/apcupsd/
<Directory "/usr/lib/cgi-bin/apcupsd">
DirectoryIndex upsstats.cgi
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex upsstats.cgi
Require all granted
</Directory>
Using vim editor to editing the website configuration file.
sudo cd /etc/apache2/sites-available/
sudo vim 000-default.conf
The configuration file section at serve-cgi-bin.conf will be like this:
Include conf-available/serve-cgi-bin.conf
# apcupsd-cgi
ScriptAlias /apcupsd/ /usr/lib/cgi-bin/apcupsd/
<Directory "/usr/lib/cgi-bin/apcupsd">
DirectoryIndex multimon.cgi
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex upsstats.cgi
Require all granted
</Directory>
Enable the CGI module
sudo a2enmod cgi
After saving the configuration file, running configtest to check syntax errors, if everything goes right, you will saw Syntax OK
pi@raspberry:/etc/apache2 $ sudo apache2ctl configtest
Syntax OK
If you saw this error, please follow the instructions below.
pi@raspberry:/etc/apache2 $ sudo apache2ctl configtest
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Syntax OK
Go back to apache configuration file.
sudo cd /etc/apache2/
sudo vim apache2.conf
Add this section
ServerName localhost
After saving the configuration file, start (or restart) apcupsd service.
sudo service apache2 start
sudo service apache2 reload
Now you can check the CGI monitor
http://your.server.address/apcupsd/
If you have multi-APC UPSes which can broadcasting data, then you can choice multimon function into index as default.
Please modify the section below
DirectoryIndex upsstats.cgi
into
DirectoryIndex multimon.cgi
The multimon.cgi will be like this
You can also modify the apache default index page, let you easier to access different function.
If apache server default folder (/var/www/html) show Permission denied alert, using the command below
sudo chown -R $USER:$USER /var/www
I was looking for APCUPSD manual, and I found this:
Connecting a Serial-Line UPS to a USB Port
By using a special adaptor, you can connect your serial-line UPS to a USB port. If you would like to free up your serial port and connect your existing serial port UPS to a USB port, it is possible if you have one of the later kernels. You simply get a serial to USB adapter that is supported by the kernel, plug it in and make one minor change to your apcupsd.conf file and away you go. (Kern adds: Thanks to Joe Acosta for pointing this out to me.)
The device that Joe Acosta and Kern are using is IOgear GUC232A USB 2 serial adapter. Bill Marr informs us that it also works with a Back-UPS Pro 650 and the 940-0095B cable.
At Kern's site, running Red Hat 7.1 with kernel 2.4.9-12, he simply changed his /etc/apcupsd/apcupsd.conf configuration line to be:
DEVICE /dev/ttyUSB0
Depending on whether or not you have hotplug working, you may need to explicitly load the kernel modules usbserial and pl2303. In Kern's case, this was not necessary.
As, at this part:
Supported UPSes and Cables
apcsmart
The 'apcsmart' protocol uses an RS232 serial connection to pass commands back and forth in a primitive language resembling modem-control codes. APC calls this language "UPS-Link". Originally introduced for Smart-UPS models (thus the name 'apcsmart'), this class of UPS is in decline, rapidly being replaced in APC's product line by USB and MODBUS UPSes.
usb
A USB UPS speaks a universal well defined control language over a USB wire. Most of APC's lineup now uses this method as of late 2003, and it seems likely to completely take over in their low- and middle range. The most recent APC UPSes support only a limited set of data over the USB interface. MODBUS (see below) is required in order to access the advanced data.
By the log output by apcupsd and dmesg, the USB-UART cable indeed using Prolific's chip, and work properly, but there is some config issue let apcupsd cannot connect with your UPS. Maybe reboot the Raspberry after change config can fix it.
Reference: