-
detect power supply
previously i was writting a code to ping a websever to check if the server was down. and now from the program i will need to check if the power supply to a server is down, if it was, the UPS will be activated to supply power.
anyone know that how i could detect the power while UPS is up using C language. what function that i should include?
-
In a Windows environment, you may want to check out WMI Win32_UninterruptiblePowerSupply.
-
-
UPS stands for what?
Theres no specific C function that will accomplish this. I would assume your going to have to parse system information saved by the operating system. Your best bet is probably to look at some source code from other projects that have done this. And see what they look for. I'm not even sure if you will be able to detect this from the sever itself. In my mind I'm thinking of a server with a backup genterator incase of power outage. which I really can't see as to how you would know where power was coming from. Unless there was some sort of switch that sent that info to the system.
but if you mean, like a laptop when its not plugged in and you can tell its running on battery, than yes its probably possible... check for projects done in KDE and GNOME, they both have power monitor things I believe...just find out the name. Grab the source and start sifting threw ( I doubt it will be an easy task ).
-
Quote:
UPS stands for what?
Uninterruptible Power Supply.
I'll make another assumption that you're probably using an APC system since IMHO, it's the dominant UPS system on the market. If so, you may want to check this APCUPSD link out. The source is available for modification.
-
i'm not quite sure that whether this can check the power...
Code:
ioctl(ups_fd, TIOCMBIS, &dtr_bit);
while(1){
ioctl(ups_fd, TIOCMGET, &flags);
if( flags & TIOCM_CAR) //DCD
{
syslog(LOG_ALERT, "Power Failure, UPS active.");
}
exit(1);
}
]
this basically is checking the serial port. so i detect the DCD port, if the ups power on meaning dcd in high and the primary power went off.