96 lines
2.2 KiB
Perl
96 lines
2.2 KiB
Perl
#!/usr/bin/perl
|
|
use feature "switch";
|
|
|
|
$USER="andre";
|
|
$PASS="mesh-assort2";
|
|
$HOST="power.andregeissler.de";
|
|
$DEVICE="Test";
|
|
$DEVICEIP="192.168.100.7";
|
|
$DEVICEUSER="admin";
|
|
$DEVICEPASS="admin";
|
|
|
|
$cmd="curl -s http://$USER:$PASS\@$HOST/$DEVICE/timer > /scripts/mFi/timer";
|
|
`$cmd`;
|
|
$cmd="dos2unix /scripts/mFi/timer";
|
|
`$cmd`;
|
|
|
|
open CTRL, "</scripts/mFi/timer";
|
|
@TIMER=<CTRL>;
|
|
close CTRL;
|
|
|
|
my $startfound=0;
|
|
my $endefound=0;
|
|
|
|
foreach (@TIMER) {
|
|
$startfound=1 if (/###START/);
|
|
$endefound=1 if (/###ENDE/);
|
|
}
|
|
exit if ($startfound == 0 || $endefound == 0);
|
|
|
|
@ports=();
|
|
@comms=();
|
|
$str="";
|
|
|
|
my $time=`date +"%H:%M"`;
|
|
chomp $time;
|
|
print "\ntime ($time)\n";
|
|
|
|
$cmd="curl -s http://$USER:$PASS\@$HOST/$DEVICE/api.php?action=getstatus";
|
|
print "get state via ($cmd)\n";
|
|
$result=`$cmd`;
|
|
chomp $result;
|
|
print "result ($result)\n";
|
|
next if ( $result eq "" );
|
|
@ports=split /;/, $result;
|
|
foreach $port (@ports) {
|
|
($dev, $state) = $port =~ /^([0-9]+):'(.*)'$/;
|
|
$ch="";
|
|
print "Check $dev\n";
|
|
$f=0;
|
|
foreach (@TIMER) {
|
|
chomp;
|
|
print ".";
|
|
if ($_ =~ /^$dev,off,$time$/) {
|
|
$f=1;
|
|
print "$dev off at $time\n";
|
|
$comm ="echo 0 > /dev/output$dev";
|
|
} elsif ($_ =~ /^$dev,on,$time$/) {
|
|
$f=1;
|
|
print "$dev on at $time\n";
|
|
$comm ="echo 1 > /dev/output$dev";
|
|
$ch="on";
|
|
} elsif ($_ =~ /^$dev,off,always$/) {
|
|
$f=1;
|
|
print "$dev always off\n";
|
|
$comm ="echo 0 > /dev/output$dev";
|
|
} elsif ($_ =~ /^$dev,on,always$/) {
|
|
$f=1;
|
|
print "$dev always on\n";
|
|
$comm ="echo 1 > /dev/output$dev";
|
|
$ch="on";
|
|
}
|
|
}
|
|
if ($f == 0) {
|
|
if ($state eq "checked") {
|
|
print "$dev on\n";
|
|
$comm="echo 1 > /dev/output$dev";
|
|
$ch="on";
|
|
} else {
|
|
print "$dev off\n";
|
|
$comm="echo 0 > /dev/output$dev";
|
|
}
|
|
}
|
|
$str .= "&oos$dev=$ch";
|
|
push(@comms, $comm);
|
|
}
|
|
$com=join(";", @comms);
|
|
|
|
$cmd="curl -s 'http://$USER:$PASS\@$HOST/$DEVICE/api.php?action=setstatus$str'";
|
|
print "set state via ($cmd)\n";
|
|
`$cmd`;
|
|
|
|
$cmd="expect /scripts/mFi/port.exp $DEVICEUSER $DEVICEIP $DEVICEPASS '$com'";
|
|
print "send commands to device\n";
|
|
`$cmd`;
|
|
|