*BSD News Article 33689


Return to BSD News archive

Xref: sserve comp.unix.bsd:14464 comp.os.linux.development:12569
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!spool.mu.edu!howland.reston.ans.net!newsserver.jvnc.net!nntp.gmd.de!dearn!barilvm!vms.huji.ac.il!shum.cc.huji.ac.il!nntpserver.huji.ac.il!hjstein
Newsgroups: comp.unix.bsd,comp.os.linux.development
Subject: UPS cable details (was Re: APC UPS owners or potential buyers, trying to show user base)
Message-ID: <HJSTEIN.94Aug1114504@sunset.huji.ac.il>
From: hjstein@sunset.huji.ac.il (Harvey J. Stein)
Date: 1 Aug 94 11:45:04
Followup-To: comp.unix.bsd,comp.os.linux.development
References: <CtpoIA.JJH@newsserver.aggregate.com>
 <31ffcm$9l6@sndsu1.sinet.slb.com><CttA8L.LBy@newsserver.aggregate.com> <31gq2p$1st@pluto.njcc.com>
Organization: Hebrew University, Jerusalem, Israel
NNTP-Posting-Host: sunset.ma.huji.ac.il
In-reply-to: bjkramer@pluto.njcc.com's message of 31 Jul 1994 14:21:13 -0400
Lines: 559

In article <31gq2p$1st@pluto.njcc.com> bjkramer@pluto.njcc.com (Brian
Kramer) writes:

   Does anyone have the wiring for a plain UPS?  I've got a non-smart one
   and cannot follow the powerd man page for the wiring.  It says things like
   connect the dtr to the dsr but neglects to say which side of the cable
   each is on or if the dtr and dsr should be connected on the same side.

   Anyone have a better worded set of instructions?

I've been saving messages discussing this, & have appended them to the
end of this message for reference.  I don't know how usefull they will
be since I never used them - I bought my cable from my UPS supplier.
Actually, I didn't buy the cable.  They swapped me the two cables (I'm
running 6 Linux machines off of 2 UPSs) for a hacked version of
powerd.c that works with their cable.  Although they were selling the
cables for $70 each (such a rip off) they were so excited to hear that
I had software that would work on *any* unix box that I probably
sold low :).

Anyway, although they considered the construction of the cable to be
proprietary information, they did admit to using a transister, some
resisters, & maybe 1 or more diodes (I can't remember).  None the
less, it seems to just be a version of what's outlined below (except
with the UPS connected to different control lines).  For my UPS,
powerd has to keep RTS high & can bring DTR high to turn off the
power.  The UPS can signal that the power went out by raising one line
& that the battery is low by raising another line (I'd say which
lines, but the source code is at work and I'm not, so I can't look it
up).  So, having a transister in the cable does not a dongle make.

Here're all the messages I've saved.  I hope their useful.  They're all
packed into a message I sent to wwar@lostlink.alt.za (Warwick Ward-Cox)
when he emailed me about the topic.  I'm including the message because
although it's somewhat redundant to what I've just said, it also includes a
hack of powerd.c that's useful for reverse-engineering UPS cables.


From hjstein Sun Jul 31 13:54:56 1994
X-VM-Attributes: Ýnil nil nil nil nil¨
Status: RO
Received: by sunset.ma.huji.ac.il id AA29533
  (5.65c/HUJI 4.152 for hjstein); Sun, 31 Jul 1994 13:54:14 +0300
Message-Id: <199407311054.AA29533@sunset.ma.huji.ac.il>
In-Reply-To: <199407272223.AA08511@sunset.ma.huji.ac.il>
From: "Harvey J. Stein" <hjstein@MATH.HUJI.AC.IL>
To: wwar@lostlink.alt.za (Warwick Ward-Cox)
Subject: Re: Powerd & UPS & Shutdown - Proper procedure for remote shutdown?
Date: Sun, 31 Jul 1994 13:54:14 +0300

"Harvey J. Stein" writes:
 > Warwick Ward-Cox writes:
 >  > What are you using to monitor the UPS signal standard serial port or UPS
 >  > card, if serial port how did you set it up software, wiring etc.  I am
 >  > wanting to attach my UPS to my Linux machine but have no idea what to do.
   ...
 > I got some additional info off the net.  I'll mail it to
 > you when I'm at work (since that's where it's stored).
 >

Here's what I sent to another enquirer:

From: "Harvey J. Stein" <hjstein@MATH.HUJI.AC.IL>
To: "Andrew J. Piziali" <andy@piziali.lonestar.org>
Subject: UPS Serial Cable
Date: Sun, 31 Jul 1994 13:49:39 +0300

"Andrew J. Piziali" writes:
 >
 > Harvey,
 >
 >    I just purchased and installed an APC Smart-UPS 400 for a home system and
 > want to wire up the UPS to the powerd to provide graceful system shutdowns.
 > APC sells cables and software but nothing for Linux, as you might imagine.
 >
 >    Would you mind sharing with me your setup, the serial cable wiring, and
 > powerd configuration?

I bought the cable that my UPS supplier was selling & between the
(slight) information I got from him & by hacking powerd I was able to
get it to work.  They wouldn't tell me how the cable is wired.  I
suggest you try to get documentation fo the cables that APC sells.  In
particular find out:

   -What lines need to be kept high.
   -What line(s) turn off the UPS.
   -What lines the UPS toggles to indicate that:
      -Power is out.
      -Battery is low.

You then need to hack powerd.c appropriately.  I hacked powerd.c into
a little program called upscheck to help when the supplier supplies
lousy info.  It allows you to set the necessary port flags from the
command line & then monitors the port, displaying the control lines
every second.  I used it as "upscheck /dev/cua1 4" to set the 3rd bit
(and clear all the other bits).  The 3rd bit is RTS which happens ot
be the line that my UPS needs to the computer to keep high.  The
original powerd.c kept DTR high which my UPS interpreted as saying
that it should shut itself off.  I'd suggest connecting the UPS to a
lamp while you fiddle with upscheck untill you get it right (lest you
inadvertently kill the power on your machine).  Anyway, here's the
upscheck.c program (which I've edited abit just now to make it
clearer, and I can't test it now, so it might not work:).  I'm also
including mail I've saved regarding how to construct UPS cables.

Good luck,

Harvey J. Stein
Berger Financial Research
hjstein@math.huji.ac.il

 --------- Begin upscheck.c ------------------
/*
 * upscheck	Check serial port lines.
 *       Was:   Monitor the DCD line of a serial port connected to
 *		an UPS. If the power goes down, notify init.
 *		If the power comes up again, notify init again.
 *		As long as the power is OK, the DCD line should be
 *		"HIGH". When the power fails, DCD should go "LOW".
 *		Powerd keeps DTR high so that you can connect
 *		DCD and DTR with a resistor of 10 Kilo Ohm and let the
 *		UPS or some relais pull the DCD line to ground.
 *
 * Usage:	powerd /dev/cua4 (or any other serial device).
 *
 * Author:	Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>.
 *
 * Version:	1.0,  15-05-1993.
 *
 *		This program was originally written for my employer,
 *			** Cistron Electronics **
 *		who has given kind permission to release this program
 *		for general puppose.
 */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>

#define PWRSTAT		"/etc/powerstatus"

/* Linux does not have SIGPWR (yet!) */
#ifndef SIGPWR
#  define SIGPWR	30
#endif

/* Tell init the power has either gone or is back. */
void powerfail(ok)
int ok;
{
  int fd;

  /* Create an info file for init. */
  unlink(PWRSTAT);
  if ((fd = open(PWRSTAT, O_CREAT|O_WRONLY, 0644)) >= 0) {
	if (ok)
		write(fd, "OK\n", 3);
	else
		write(fd, "FAIL\n", 5);
	close(fd);
  }
  kill(1, SIGPWR);
}

/* Main program. */
int main(int argc, char **argv)
{
  int fd;

/*  These TIOCM_* parameters are defined in <linux/termios.h>, which  */
/*  is indirectly included here.                                      */
  int dtr_bit = TIOCM_DTR;
  int rts_bit = TIOCM_RTS;
  int set_bits;
  int flags;
  int status, oldstat = -1;
  int count = 0;
  int pc;

  if (argc < 2) {
	fprintf(stderr, "Usage: upscheck <device> <bits-to-set>\n");
	exit(1);
  }

  /* Open monitor device. */
  if ((fd = open(argvÝ1¨, O_RDWR | O_NDELAY)) < 0) {
    fprintf(stderr, "upscheck: %s: %s\n", argvÝ1¨, sys_errlistÝerrno¨);
    exit(1);}

  /* Line is opened, so DTR is high. Force it anyway to be sure. */
  /*    ioctl(fd, TIOCMBIS, &dtr_bit); */
  /*    The above line was from the original powerd.c, but it turned off */
  /*    my UPS!  So, I changed it to the line below which clears the DTR */
  /*    instead of setting the DTR bit & that worked for me.  However,   */
  /*    it might not work for you, so I commented it out too.            */
  /*    ioctl(fd, TIOCMBIC, &dtr_bit); */

  /* Get the bits to set from the command line. */
  sscanf(argvÝ2¨, "%d", &set_bits);

  while (1) {
    /* Set the command line specified bits (& only the command line */
    /* specified bits).                                             */
    ioctl(fd, TIOCMSET, &set_bits);
    fprintf(stderr, "Setting %o.\n", set_bits);

    sleep(1);

    /* Get the current line bits */
    ioctl(fd, TIOCMGET, &flags);
    fprintf(stderr, "Flags are %o.\n", flags);

/*  Fiddle here by changing TIOCM_CTS to some other TIOCM until    */
/*  this program detects that the power goes out when you yank     */
/*  the plug on the UPS.  Then you'll know how to modify powerd.c. */
    if (flags & TIOCM_CTS)
      {
	pc = 0 ;
	fprintf(stderr, "power is up.\n");
      }
    else
      {
	pc = pc + 1 ;
	fprintf(stderr, "power is down.\n");
      }
    }

  close(fd);
}
 ----------- End upscheck.c ---------------------------

 --------- Begin miscellaneous mail messages about UPS control -----
>From miquels@drinkel.nl.mugnet.org Thu Mar 10 15:07:01 1994
Newsgroups: comp.os.linux.help
Subject: Re: auto-shutdown with UPS
From: miquels@drinkel.nl.mugnet.org (Miquel van Smoorenburg)
Date: Tue, 01 Mar 94 18:39:19 MET
Distribution: world
Organization: Organized? Me?
X-News-Software: W-NEWS Release 4.4.3 for Linux/PRO

In article <CRAFFERT.94Feb28125452@nostril.lehman.com> craffert@nostril.lehman.com (Colin Owen Rafferty) writes:
>I am about to buy an Uninterruptable Power Supply for my machine, and
>I would like to get one that has the "auto-shutdown" feature.
>
>I assume that these each have some kind of serial connection that
>tells the system information about it.
>
>Has anyone written a package that watches the UPS and does a shutdown
>(or something) when the power is off?
>

SysVinit includes a `powerd' - power daemon that watches the serial port.
I heared some rumours that with kernels >= pl15 the modem control signals
(DCD et al) are not being watched properly by the kernel, but I haven't
checked that myself. Anyway, for the powerd to work you will need to
make a special cable yourself - or change the source code. Instructions
are included.

Mike.
--
| Miquel van Smoorenburg        | "I know one million ways, to always pick |
| miquels@drinkel.nl.mugnet.org |  the wrong fantasy" - the Black Crowes.  |


>From hennus@sky.nl.mugnet.org Thu Mar 10 15:10:22 1994
Newsgroups: comp.os.linux.help
Subject: Re: auto-shutdown with UPS
From: hennus@sky.nl.mugnet.org (Hennus Bergman)
Date: Tue, 1 Mar 1994 22:17:45 GMT
Distribution: world
Organization: The Organization For Removal Of On-Screen Logos

In article <CRAFFERT.94Feb28125452@nostril.lehman.com>,
Colin Owen Rafferty <craffert@nostril.lehman.com> wrote:
>I am about to buy an Uninterruptable Power Supply for my machine, and
>I would like to get one that has the "auto-shutdown" feature.
>
I just got one of those real cheap :-)
It's a GPS1000 by ACCODATA. Anybody know how good the output
signal of these things is? ÝDon't have a scope myself :-(¨

>I assume that these each have some kind of serial connection that
>tells the system information about it.
>
I took it apart to find out how it worked. There were three optocouplers
(two output, one input) connected to a 9 pin connector at the back.
One turns on when the power fails, and goes off again when the power
returns. While the power is off, you can use the `input' to shut the
battery off. ÝIt releases the power-relay.¨ The third one is some kind
of feedback to tell that it did accepted the `shut-down command'.
I think the interface for my UPS was designed to be connected to TTL-level
signals, but with some resistors it could be connected to serial port.
It's wired in such a way that using a RS-232 port you cannot use both
output optocouplers; but the shutdown feedback is not necessary anyway,
just use the important one. ;-)
ÝNote that it is possible to blow the transistor part in optocouplers
with RS-232 levels if you wire it the wrong way round ;-)¨

I was hoping I would be able to connect it to my unused game port,
but that doesn't have an output, does it?
I'll probably end up getting an extra printer port for this.

Not all UPS' use optocouplers, some use simple relays, which are
less critical to connect, but of course not as `nice'.

>Has anyone written a package that watches the UPS and does a shutdown
>(or something) when the power is off?
SysVinit-2.4 (and probably 2.5 as well) has a `powerd' daemon that
continually watches a serial port for presence of the CD (Carrier
Detect) line and signals init when it drops. Init then activates
shutdown with a time delay. If the power returns within a few minutes
the shutdown is cancelled. Very Nice.
The only problem I had with it is that it doesn't actually tell the
UPS to turn off when the shutdown is complete. It just sits there with
a root prompt. I'll probably write a small program to shut it down
>from /etc/brc. RSN.

>	Colin Rafferty, Lehman Brothers <craffert@lehman.com>

Hennus Bergman


>From miquels@caution.cistron.nl.mugnet.org Wed Jul 21 14:26:33 1993
Newsgroups: comp.os.linux
Subject: Re: UPS interface for Linux?
From: miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg)
Date: Sat, 17 Jul 93 18:03:37
Distribution: world
Organization: Cistron Electronics.

In article <1993Jul15.184450.5193@excaliber.uucp> joel@rac1.wam.umd.edu (Joel M. Hoffman) writes:
>I'm in the process of buying a UPS (Uninteruptable Power Supply), and
>notice that some of them have interfaces for LAN's to signal the LAN
>when the power fails.
>
>Is there such an interface for Linux?
>
>Thanks.
>
>-Joel
>(joel@wam.umd.edu)
>

When I worked on the last versioon of SysVinit (Now version 2.4),
I temporarily had a UPS on my computer, so I added support for it.
You might have seen that in the latest <signal.h> header files there
is a #define SIGPWR 30 now :-). Anyway, I did not have such a special
interface but the output of most UPS's is just a relais that makes or breaks
on power interrupt. I thought up a simple way to connect this to the
DCD line of the serial port. In the SysVinit package there is a daemon
called 'powerd' that keeps an eye on that serial line and sends SIGPWR
to init when the status changes, so that init can do something (such as
bringing the system down within 5 minutes). How to connect the UPS to
the serial line is described in the source "powerd.c", but I will
draw it here for explanation:

                     +------------------------o  DTR
                     |
                   +---+
                   |   | resistor
                   |   | 10 kilo-Ohm
                   |   |
                   +---+                                To serial port.
                     |
       +-----o-------+------------------------o  DCD
       |             |
       o  UPS        |
     \    relais     |
      \              |
       |             |
       +-----o-------+------------------------o  GND

Nice drawing eh?

Hope this helps.
SysVinit can be found on sunsite (and tsx-11 probably) as
SysVinit2.4.tar.z

Mike.

--

Miquel van Smoorenburg, <miquels@cistron.nl.mugnet.org>
Ibmio.com: cannot open CONFIG.SYS: file handle broke off.


>From danny@caution.cistron.nl.mugnet.org Wed Jul 21 14:27:04 1993
Newsgroups: comp.os.linux
Subject: Re: UPS interface for Linux?
From: danny@caution.cistron.nl.mugnet.org (Danny ter Haar)
Date: Mon, 19 Jul 93 11:02:14
Distribution: world
Organization: Cistron Electronics.

In article <9307174330@caution.cistron.nl.mugnet.org> miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg) writes:
>How to connect the UPS to the serial line is described in the source
>"powerd.c", but I will draw it here for explanation:

The drawing wasn't really clear, please use this one in stead !
>
>                     +------------------------o  DTR
>                     |
>                   +---+
>                   |   | resistor
>                   |   | 10 kilo-Ohm
>                   |   |
>                   +---+                                To serial port.
>                     |
>       +-----o-------+------------------------o  DCD
>       |
>       o  UPS
>     \    relais
>      \
>       |
>       +-----o--------------------------------o  GND
>

The DTR is kept high, when the UPS's power input is gone it
will close the relais . The computer is monitoring
the DCD input port to go LOW . When this happens it will start a
shutdown sequence...

_____
Danny

--
<=====================================================================>
Danny ter Haar  <dannyth@hacktic.nl> or <danny@cistron.nl.mugnet.org>
Robins law #103: 'a couple of lightyears can't part good friends'


>From miquels@caution.cistron.nl.mugnet.org Wed Jul 21 14:27:41 1993
Newsgroups: comp.os.linux
Subject: Re: Help with dosemu0.49
From: miquels@caution.cistron.nl.mugnet.org (Miquel van Smoorenburg)
Date: Mon, 19 Jul 93 02:43:01
Distribution: world
Organization: Cistron Electronics.

In article <22aka6$f80@bach.seattleu.edu> aehall@calvin.seattleu.edu (OUTTA HERE!) writes:
>In article <1993Jul17.194655.1@vax.sonoma.edu> levinson@vax.sonoma.edu writes:
>>I have installed gcc2.4.3 on my system (gcc-2.4.3.main.tar.z, plus objc and
>>info) and the corresponding library images, image-4.4.1, extra and inc)
>>
>>When I make install on dosemu 0.49, after the long ld line it says:
>>ld: No such file or directory for libipc
>>
>>Anyone have any hints on this?  I followed the install instructions for the
>>gcc, lib and dosemu to the bone and can't figure out what it is asking for.
>>
>
>Is libipc one of the libraries in /usr/lib?
>I have the same problem, but haven't been able to hunt down libipc.
>
>Anyone know where it is?
>
>
Yes. It's in lipipc.a, but in the newer Linux releases (99.10, 99.11)
you are supposed to have it in the C library. Before 99.9 or .8,
the IPC patches were separate and therefore the library was also.
If you use the newest kernel (>=99.10) and libraries (>= 4.4) you
can forget about -lipc.a because it's in libc.a

Mike.


--

Miquel van Smoorenburg, <miquels@cistron.nl.mugnet.org>
Ibmio.com: cannot open CONFIG.SYS: file handle broke off.


>From michael.livsey@canrem.com Wed Jul 21 14:32:12 1993
Newsgroups: comp.os.linux
Subject: UPS interface for Linux?
From: michael.livsey@canrem.com (Michael Livsey)
Date: Tue, 20 Jul 93 21:59:00 -0400
Distribution: world
Organization: CRS Online  (Toronto, Ontario)

<<***** On 07-17-93, JOEL M. HOFFMAN wrote to ALL: *****>>

JM>I'm in the process of buying a UPS (Uninteruptable Power Supply), and
JM>notice that some of them have interfaces for LAN's to signal the LAN
JM>when the power fails.
JM>
JM>Is there such an interface for Linux?

I recently wrote such a program for Solaris to monitor a UPS and issue SNMP
traps, wall messages and halt the system after a specified timeout. I'll
post the source if requested.

The basic concept behind a UPS monitor is simple. Connect the trigger wire
to the DCD on your serial port (pin 8 on a DB25). The monitor program does
an open on the port and blocks until it receives a carrier detect (the UPS
trigger is active i.e. on battery power). This causes the open to succeed at
which point you're on battery power and can act accordingly.

The secret to getting the program to work is to disable software carrier
detect for the serial port and kill any getties on the port. Hardware
carrier detect forces the open on the port to block until carrier detect is
active. If software carrier is enabled, the open will succeed immediately.
As I'm not a Linux user (yet), I'm not sure how to enforce hardware carrier
detect on a port.

Regards.


michael.livsey@canrem.com


---
 ~ VbReader 1.5 #12 ~ A big enough hammer can usually fix anything.

>From aehall@calvin.seattleu.edu Wed Jul 21 14:32:18 1993
Newsgroups: comp.os.linux
Subject: Re: UPS interface for Linux?
From: aehall@calvin.seattleu.edu (OUTTA HERE!)
Date: 21 Jul 93 04:01:12 GMT
Distribution: world
Organization: Lasciate ogni speranza, voi que entrate.
NNTP-Posting-Host: calvin.seattleu.edu

In article <60.38085.2707.0N17F37F@canrem.com> michael.livsey@canrem.com (Michael Livsey) writes:
><<***** On 07-17-93, JOEL M. HOFFMAN wrote to ALL: *****>>
>
>JM>I'm in the process of buying a UPS (Uninteruptable Power Supply), and
>JM>notice that some of them have interfaces for LAN's to signal the LAN
>JM>when the power fails.
>JM>
>JM>Is there such an interface for Linux?
>
>I recently wrote such a program for Solaris to monitor a UPS and issue SNMP
>traps, wall messages and halt the system after a specified timeout. I'll
>post the source if requested.
Ýsnip¨

I'm pretty sure the SysV init package will monitor a serial port for an UPS.

(I don't have a UPS, so I'm not certain.)

A

--
Anthony Hall                             _   _   Unix System Administrator
aehall@seattleu.edu                     /_/ /_/ Physician Micro Systems, Inc.
                                       _   _   2033 6th Ave Suite 707
                                      /_/ /_/ Seattle, WA 98122  206-441-8490


--
Harvey J. Stein
Berger Financial Research
hjstein@math.huji.ac.il