initial commit

This commit is contained in:
Luc Bijl 2022-10-17 20:02:47 +02:00
commit c40b764756
8 changed files with 972 additions and 0 deletions

51
configfiles/ups.c Normal file
View file

@ -0,0 +1,51 @@
#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;
}