Difference between revisions of "APC Smart-UPS"

From TheBeard Science Project Wiki
Jump to: navigation, search
(Finding Your Serial Port)
(Finding Your Serial Port)
Line 85: Line 85:
 
</pre>
 
</pre>
  
I found that <code>/dev/serial</code> did not work, so I used </code>/dev/ttyUSB0</code>.
+
I found that <code>/dev/serial</code> did not work, so I used <code>/dev/ttyUSB0</code>.
  
 
== <html><a name="Configuring-Apcupsd"></a></html> Configuring Apcupsd ==
 
== <html><a name="Configuring-Apcupsd"></a></html> Configuring Apcupsd ==

Revision as of 23:25, 24 August 2020

The following information applies to all APC Smart-UPS models. Most of this I personally tested using a Smart-UPS SC 1500 and a Smart-UPS 2200 (both are rack mount units).

Console Cables

To configure a Smart-UPS, you need to connect via console cable. Depending on your model, the unit may have a USB port, serial port, or both.

USB to RJ50 Cable

The Smart-UPS uses a non-standard USB to RJ50 cable, which looks similar to an RJ45 but has 10 pins instead of 8. You might need to order a cable directly from APC or find a used one. The model number I ordered was AP9827 940-0127E and I can confirm it works on both Smart-UPS SC 1500 and 2200.

AP9827 940-0127E.jpg

If you happen to have an RJ50 connector and a spare USB cable, you could make your own with the following pinout:

APC USB Pinout.jpg

Serial Cable

IMPORTANT: You CANNOT connect a normal serial cable to the Smart-UPS. If you do connect a normal serial cable and terminate both ends, the Smart-UPS will likely shut down or exhibit other strange behaviors.

The cable required for a serial port on a Smart-UPS is also proprietary and has a non-standard pinout. You need a "Smart Signalling" capable serial cable (RS-232). The model number I ordered was 940-1524C and I can confirm it works with the Smart-UPS SC 1500 and 2200. Note that the "15" in that model number is the length of the cable, so any model that varies in those digits will work the same.

If you want to create your own serial cable, you will need a male DB9 connector and a female DB9 connector. Wire them up with the following pinout:

APC Serial Pinout.jpg

Monitoring Using PowerChute (Windows)

Monitoring Using Apcupsd (Linux)

Apcupsd is an open source alternative to APC's PowerChute software for monitoring and configuring APC UPS devices. You can install it using you package manager. Note: The following tutorials were performed on Debian-based Linux.

Install using apt-get:

sudo apt-get install apcupsd

Finding Your Serial Port

Before you can configure apcupsd, you will need to figure out what serial port you're connected to. This is easy if you have only one serial device. The device file will be named something like /dev/ttySN where N is a number. Most likely you will have many serial ttys in the /dev directory, but most of them will not actually have a recognized UART device attached.

To find which serial devices have a UART, you can run to following command:

sudo less /proc/tty/driver/serial

You will see an output similar this:

0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
1: uart:unknown port:000002F8 irq:3
2: uart:unknown port:000003E8 irq:4
3: uart:unknown port:000002E8 irq:3
4: uart:ST16650V2 port:0000E030 irq:16 tx:0 rx:0
5: uart:ST16650V2 port:0000E020 irq:17 tx:121720 rx:670672 brk:4
6: uart:unknown port:00000000 irq:0
...

Ignore the ones that say "unknown." The ones that actually have a UART device will display the UART model. If you have more than one, you might need to use a process of elimination. I happen to know that my device is on line 5. The number on the far left corresponds to the device number N in the file name /dev/ttySN. So I will configure apcupsd to use the device /dev/ttyS5. If you're not sure which device is the right one, you can go ahead and continue Configuring Apcupsd as I've specified in the following sections, and then follow the steps in Reading UPS Status to figure out if you've chosen the right device number.

If you're using a serial to USB adapter, you can run the following command:

sudo less /proc/tty/driver/usbserial

You should look for the port: in the following output:

usbserinfo:1.0 driver:2.0
1: module:ch341 name:"ch341-uart" vendor:1a86 product:7523 num_ports:1 port:0 path:usb-0000:00:1d.0-1.2

Mine shows port:0 which corresponds to /dev/ttyUSB0.

Another way you can do it, because USB serial devices only show up in /dev when they are connected, is to see which files appear when you plug in you device. Leave the cable unplugged from your computer, then run the command below. It will print a newline and pause. While it's paused plug in the cable then press Enter:

diff <(ls /dev) <(read;ls /dev)|grep ">"

You will see output like this:

> serial
> ttyUSB0

I found that /dev/serial did not work, so I used /dev/ttyUSB0.

Configuring Apcupsd

Before you start the apcupsd service there are a couple files you need to edit.

Edit the file /etc/apcupsd/apcupsd.conf and change the following lines to fit your needs:

UPSCABLE usb
UPSTYPE usb
DEVICE /dev/ttyS0

The file contains comments that very thoroughly explain what parameters are available for each option.

I found that if I'm using a USB cable, I need to set the DEVICE to /dev/ttyUSB0.

If you're using a serial cable, the UPSCABLE option needs to have the right model and UPSTYPE should be "apcsmart". Then set the DEVICE option to device file.

Here are my settings for serial:

UPSCABLE 940-1524C
UPSTYPE apcsmart
DEVICE /dev/ttyS5

If you're using a Smart serial cable with a serial-to-USB adapter, I found that these configurations worked:

UPSCABLE 940-1524C
UPSTYPE apcsmart
DEVICE /dev/ttyUSB0

Now you need to edit the file /etc/default/apcupsd.

Set the value to "yes":

ISCONFIGURED=yes

You are now ready to start the apcupsd service.

Starting/Stopping Apcupsd

Start apcupsd:

sudo systemctl start apcupsd

Stop apcupsd:

sudo systemctl stop apcupsd

Reading UPS Status

Once you have apcupsd configured and running, you can get a readout of information about the UPS by running the command:

sudo apcaccess

If your APC is connected properly, you will see an output like this:

APC      : 001,048,1107
DATE     : 2020-07-27 22:05:34 -0700
HOSTNAME : neuromancer
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : UPS_IDEN
CABLE    : Custom Cable Smart
DRIVER   : APC Smart UPS (any)
UPSMODE  : Stand Alone
STARTTIME: 2020-07-27 22:05:27 -0700
MODEL    : Smart-UPS SC1500
STATUS   : ONLINE
LINEV    : 122.0 Volts
LOADPCT  : 0.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 956.0 Minutes
...

If your APC is not connected, you will get a bunch of nonsense values, such as 0 volts, and the STATUS might be blank. This is how you know if you have configured apcupsd with the correct serial port. Note that it takes about 10 seconds after starting the apcupsd service before you will see proper values when running the apcaccess command.

Accessing UPS Configuration Terminal

The configuration terminal allows you to make configuration changes and perform a runtime calibration.

First you must stop the ascupsd service if it's running:

sudo systemctl stop apcupsd

Now run the apctest command:

sudo apctest

You will be presented with several options:

1) Query the UPS for all known values
2) Perform a Battery Runtime Calibration
3) Abort Battery Calibration
4) Monitor Battery Calibration progress
5) Program EEPROM
6) Enter TTY mode communicating with UPS
Q) Quit

Software Runtime Calibration

Calibrating the APC makes sure that the system has a good estimate of how long the unit can run on the installed batteries with a given load. You should perform a calibration about once or twice a year and every time you install new batteries.

Procedure:

  1. Make sure the batteries are fully charged.
  2. Plug a device into the APC that draws at least a 30% load and will not fluctuate by more than +/- 5%. Do not use an essential device as the calibration process will cause an abrupt shutdown. Something like lamps or a TV will do.
  3. Connect your PC to the APC via serial or USB cable.
  4. Stop the apcupsd service if it is running.
  5. Run the command sudo apctest.
  6. From the terminal, choose the option 2) Perform a Battery Runtime Calibration.
  7. The batteries will drain entirely and the APC will eventually reboot and start charging the batteries again. This process must not be interrupted.
  8. Once the batteries are fully changed, the calibration is complete.

Manual Runtime Calibration

This procedure is an alternative to the runtime calibration.

Procedure:

  1. With batteries installed, plug the unit into a power outlet and leave it on and charging for at least 24 hours.
  2. Disconnect any serial or USB cables from the unit.
  3. Plug a device into the APC that draws at least a 30% load and will not fluctuate by more than +/- 5%. Do not use an essential device as the calibration process will cause an abrupt shutdown. Something like lamps or a TV will do.
  4. Disconnect the APC from the wall outlet to force it to run on battery power.
  5. Allow the APC to run on batteries until it completely shuts off.
  6. Remove the load drawing devices and plug the APC back into the wall outlet.
  7. Allow the APC to charge until the batteries are fully charged. It will charge quicker if the unit is turned off.

Line Input Sensitivity

The APC senses irregularities in the power input and will switch to batteries power if the irregularities go beyond a certain threshold. Using the configuration terminal you can change the sensitivity of this threshold.

The reason you might do this is if you have an old unit the capacitors in the sensing circuit might be wearing out and falsely triggering the failover. If this is happening to your unit, you might see it flapping back and forth between line and battery power, or it may even be stuck on battery power. If this is the case, you can try lowering the sensitivity using this procedure.

First you can check the current sensitivity setting:

  1. Connect your PC to the APC via serial or USB cable.
  2. Make sure apcupsd is running.
  3. Run the command sudo apcaccess.
  4. Look for the line SENSE  : High. The possible values are High, Medium, and Low.

To change the sensitivity setting:

  1. Connect your PC to the APC via serial or USB cable.
  2. Stop the apcupsd service if it is running.
  3. Run the command sudo apctest.
  4. From the terminal, choose the option 5) Program EEPROM.
  5. Choose the option 4) Change sensitivity.
  6. At the prompt "Enter new sensitivity:" enter either a capital "H" (high), "M" (medium), or "L" (low). It will take a few seconds.
  7. You can now exit, start apcupsd again, and run the apcaccess command to confirm the change.

If setting it to medium doesn't work, try setting to to low. If this does not solve your problem, you're looking at needing to replace capacitors.

Converting a 2-Battery UPS to a 4-Battery UPS

For a long time, I had an APC Smart-UPS SC 1500, which holds 4 batteries. When it started having issues I discovered that you can buy the cheaper model APC Smart-UPS SN 1000, which holds 2 batteries, and it's actually trivial to convert it to a 4-battery unit.

If you open up the case and look in the battery bay you will see a metal plate. Simply remove this plate. That's it!

APC SN1000 Plate.jpg

The only additional thing you need to do is perform a Software Runtime Calibration or a Manual Runtime Calibration with the new batteries installed.

Also, if you're going to wire up your own battery harness, see the Battery Wiring section.

Battery Wiring

2-Battery Wiring

APC Smart-UPS 2-Battery Wiring Diagram.jpg

4-Battery Wiring

APC Smart-UPS SC1500 Battery Wiring Diagram.jpg

Event Handling and Notifications

When an event occurs, apcupsd will run the script /etc/apcupsd/apccontrol with a command line argument that invokes code within the corresponding switch case (read the script to see the available arguments).

Before apcupsd invokes apccontrol, it will look for a file in /etc/apcupsd that has the same name as the command line argument that it will pass to apccontrol and run that script first. For example, before apcupsd invokes /etc/apcupsd/apccontrol doshutdown it will look for a file called /etc/apcupsd/doshutdown and run it if it exists. This way you can easily customize notifications and other actions to occur before apcupsd shuts your computer down.

Another example: when the batteries need to be changed apcupsd will run the script /etc/apcupsd/changeme. Edit this script to add a customized notification. I added some code to send me a text message.

If you create a new script, be sure it has the correct ownership and permissions (according to the permissions of the scripts that are installed with apcupsd):

cd /etc/apcupsd
touch doshutdown
chown root:root doshutdown
chmod 755 doshutdown

Disable Terminal Messages (Wall)

Apcupsd uses the wall command to push a message to the terminals of every user on the system. If you don't want this, you can edit the file /etc/apcupsd/apccontrol and replace the line:

WALL=wall

With:

WALL=:

3D Printed Parts

Modular Battery Harness (2-battery or 4-battery): https://www.thingiverse.com/thing:4578235
DSC06104.JPG

Links And Files