51 lines
1,019 B
C
51 lines
1,019 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int main()
|
|
{
|
|
unsigned int chargelim = 80;
|
|
unsigned int charge = 100;
|
|
|
|
unsigned int voltagelim = 210;
|
|
unsigned int voltage = 240;
|
|
|
|
|
|
FILE *fp;
|
|
char path[1024];
|
|
|
|
while(charge > chargelim || voltage > voltagelim)
|
|
{
|
|
sleep(20);
|
|
fp = popen("/usr/bin/upsc ups@{domain} battery.charge 2>&1 |grep -v 'Init SSL'", "r");
|
|
|
|
if(fgets(path, sizeof(path), fp) != NULL)
|
|
{
|
|
charge = atoi(path);
|
|
pclose(fp);
|
|
}
|
|
else
|
|
{
|
|
pclose(fp);
|
|
system("poweroff");
|
|
}
|
|
|
|
fp = popen("/usr/bin/upsc ups@{domain} input.voltage 2>&1 |grep -v 'Init SSL'", "r");
|
|
|
|
if(fgets(path, sizeof(path), fp) != NULL)
|
|
{
|
|
voltage = atoi(path);
|
|
pclose(fp);
|
|
}
|
|
else
|
|
{
|
|
pclose(fp);
|
|
system("poweroff");
|
|
}
|
|
}
|
|
|
|
system("poweroff");
|
|
|
|
return 0;
|
|
}
|