mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
74_HOMBOT: add commandref summary, code design
git-svn-id: https://svn.fhem.de/fhem/trunk@16458 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d1bc9e423a
commit
b2e0d5ad31
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- added: 74_HOMBOT: add commandref summary, code design
|
||||||
- change: 73_GardenaSmartBridge: change logging output for username and
|
- change: 73_GardenaSmartBridge: change logging output for username and
|
||||||
password
|
password
|
||||||
- feature: 93_DbRep: 7.14.6, attr expimpfile can use some kinds of wildcards
|
- feature: 93_DbRep: 7.14.6, attr expimpfile can use some kinds of wildcards
|
||||||
|
@ -157,6 +157,7 @@ sub EQ3BT_Initialize($) {
|
|||||||
$hash->{SetFn} = 'EQ3BT_Set';
|
$hash->{SetFn} = 'EQ3BT_Set';
|
||||||
$hash->{AttrFn} = 'EQ3BT_Attribute';
|
$hash->{AttrFn} = 'EQ3BT_Attribute';
|
||||||
$hash->{AttrList} = 'sshHost maxRetries timeout '.
|
$hash->{AttrList} = 'sshHost maxRetries timeout '.
|
||||||
|
'blockingCallLoglevel:2,3,4,5 '.
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -172,6 +173,7 @@ sub EQ3BT_Define($$) {
|
|||||||
|
|
||||||
$hash->{STATE} = "initialized";
|
$hash->{STATE} = "initialized";
|
||||||
$hash->{VERSION} = "2.0.4";
|
$hash->{VERSION} = "2.0.4";
|
||||||
|
$hash->{loglevel} = 4;
|
||||||
Log3 $hash, 3, "EQ3BT: EQ-3 Bluetooth Thermostat ".$hash->{VERSION};
|
Log3 $hash, 3, "EQ3BT: EQ-3 Bluetooth Thermostat ".$hash->{VERSION};
|
||||||
|
|
||||||
if (int(@a) > 4) {
|
if (int(@a) > 4) {
|
||||||
@ -236,13 +238,22 @@ sub EQ3BT_pairDevice {
|
|||||||
|
|
||||||
sub EQ3BT_Attribute($$$$) {
|
sub EQ3BT_Attribute($$$$) {
|
||||||
my ($mode, $devName, $attrName, $attrValue) = @_;
|
my ($mode, $devName, $attrName, $attrValue) = @_;
|
||||||
|
my $hash = $defs{$devName};
|
||||||
|
|
||||||
if($mode eq "set") {
|
if($mode eq "set") {
|
||||||
|
if( $attrName eq "blockingCallLoglevel" ) {
|
||||||
|
$hash->{loglevel} = $attrValue;
|
||||||
|
Log3 $devName, 3, "EQ3BT ($devName) - set blockingCallLoglevel to $attrValue";
|
||||||
|
}
|
||||||
|
|
||||||
} elsif($mode eq "del") {
|
} elsif($mode eq "del") {
|
||||||
|
if( $attrName eq "blockingCallLoglevel" ) {
|
||||||
|
$hash->{loglevel} = 4;
|
||||||
|
Log3 $devName, 3, "EQ3BT ($devName) - set blockingCallLoglevel to default";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +392,7 @@ sub EQ3BT_setDesiredTemperature($$) {
|
|||||||
|
|
||||||
my $eq3Temp = sprintf("%02X", $desiredTemp * 2);
|
my $eq3Temp = sprintf("%02X", $desiredTemp * 2);
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setDesiredTemperature|0x0411|41".$eq3Temp, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setDesiredTemperature|0x0411|41".$eq3Temp, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +416,7 @@ sub EQ3BT_setBoost {
|
|||||||
my $data = "01";
|
my $data = "01";
|
||||||
$data = "00" if($onoff eq "off");
|
$data = "00" if($onoff eq "off");
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setBoost|0x0411|45".$data, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setBoost|0x0411|45".$data, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +440,7 @@ sub EQ3BT_setMode {
|
|||||||
my $data = "40";
|
my $data = "40";
|
||||||
$data = "00" if($mode eq "automatic");
|
$data = "00" if($mode eq "automatic");
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setMode|0x0411|40".$data."|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setMode|0x0411|40".$data."|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +461,7 @@ sub EQ3BT_setEco {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setEco|0x0411|44|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setEco|0x0411|44|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +482,7 @@ sub EQ3BT_setComfort {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setComfort|0x0411|43|listen", "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setComfort|0x0411|43|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,29 +501,35 @@ sub EQ3BT_setComfortRetry {
|
|||||||
### Gatttool functions ###
|
### Gatttool functions ###
|
||||||
sub EQ3BT_retryGatttool {
|
sub EQ3BT_retryGatttool {
|
||||||
my ($hash, $workType) = @_;
|
my ($hash, $workType) = @_;
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $hash->{NAME}."|".$hash->{MAC}."|$workType|".$hash->{helper}{"handle$workType"}."|".$hash->{helper}{"value$workType"}."|".$hash->{helper}{"listen$workType"}, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $hash->{NAME}."|".$hash->{MAC}."|$workType|".$hash->{helper}{"handle$workType"}."|".$hash->{helper}{"value$workType"}."|listen", "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub EQ3BT_execGatttool($) {
|
sub EQ3BT_execGatttool($) {
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
my ($name, $mac, $workType, $handle, $value, $listen) = split("\\|", $string);
|
my ($name, $mac, $workType, $handle, $value, $listen) = split("\\|", $string);
|
||||||
my $wait = 1;
|
|
||||||
my $hash = $main::defs{$name};
|
|
||||||
|
|
||||||
my $gatttool = qx(which gatttool);
|
my $hash = $main::defs{$name};
|
||||||
|
|
||||||
|
my $gatttool = qx(which gatttool);
|
||||||
chomp $gatttool;
|
chomp $gatttool;
|
||||||
|
|
||||||
if(-x $gatttool) {
|
if(-x $gatttool) {
|
||||||
my $gtResult;
|
my $gtResult;
|
||||||
my $cmd;
|
my $cmd;
|
||||||
|
my $wait = 1;
|
||||||
my $sshHost = AttrVal($name,"sshHost","none");
|
my $sshHost = AttrVal($name,"sshHost","none");
|
||||||
|
my $hciDevice = "hci".$hash->{helper}{hcidevices}[$hash->{helper}{currenthcidevice}];
|
||||||
|
|
||||||
|
|
||||||
while($wait) {
|
while($wait) {
|
||||||
my $grepGatttool = qx(ps ax| grep -E \'gatttool -b $mac\' | grep -v grep);
|
|
||||||
|
my $grepGatttool;
|
||||||
|
$grepGatttool = qx(ps ax| grep -E \'gatttool -i $hciDevice -b $mac\' | grep -v grep) if($sshHost eq 'none');
|
||||||
|
$grepGatttool = qx(ssh $sshHost 'ps ax| grep -E "gatttool -i $hciDevice -b $mac" | grep -v grep') if($sshHost ne 'none');
|
||||||
|
|
||||||
if(not $grepGatttool =~ /^\s*$/) {
|
if(not $grepGatttool =~ /^\s*$/) {
|
||||||
#another gattool is running
|
Log3 $name, 4, "EQ3BT ($name) - ExecGatttool_Run: another gatttool process is running. waiting...";
|
||||||
Log3 $name, 5, "EQ3BT ($name): another gatttool process is running. waiting...";
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
} else {
|
} else {
|
||||||
$wait = 0;
|
$wait = 0;
|
||||||
@ -525,26 +542,16 @@ sub EQ3BT_execGatttool($) {
|
|||||||
$value .= $currentDate;
|
$value .= $currentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $hciDevice = "hci".$hash->{helper}{hcidevices}[$hash->{helper}{currenthcidevice}];
|
|
||||||
#my $cmd = "gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value";
|
|
||||||
if( $sshHost ne 'none' ) {
|
|
||||||
$cmd = "ssh $sshHost 'gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value";
|
|
||||||
} else {
|
|
||||||
$cmd = "gatttool -b $mac -i $hciDevice --char-write-req --handle=$handle --value=$value";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(defined($listen) && $listen eq "listen") {
|
$cmd = "ssh $sshHost '" if($sshHost ne 'none');
|
||||||
$cmd = "timeout ".AttrVal($name, "timeout", 15)." ".$cmd." --listen";
|
$cmd .= "timeout 10 " if(defined($listen) and $listen eq "listen");
|
||||||
}
|
$cmd .= "gatttool -i $hciDevice -b $mac ";
|
||||||
|
$cmd .= "--char-write-req -a $handle -n $value";
|
||||||
#redirect stderr to stdout
|
$cmd .= " --listen" if(defined($listen) and $listen eq "listen");
|
||||||
if( $sshHost ne 'none' ) {
|
$cmd .= " 2>&1 /dev/null";
|
||||||
$cmd .= " 2>&1'";
|
$cmd .= "'" if($sshHost ne 'none');
|
||||||
} else {
|
|
||||||
$cmd .= " 2>&1";
|
|
||||||
}
|
|
||||||
|
|
||||||
Log3 $name, 5, "EQ3BT ($name): $cmd";
|
Log3 $name, 4, "EQ3BT ($name): $cmd";
|
||||||
$gtResult = qx($cmd);
|
$gtResult = qx($cmd);
|
||||||
chomp $gtResult;
|
chomp $gtResult;
|
||||||
my @gtResultArr = split("\n", $gtResult);
|
my @gtResultArr = split("\n", $gtResult);
|
||||||
@ -554,7 +561,7 @@ sub EQ3BT_execGatttool($) {
|
|||||||
if(defined($gtResultArr[1]) && $gtResultArr[1] =~ /Notification handle = 0x0421 value: (.*)/) {
|
if(defined($gtResultArr[1]) && $gtResultArr[1] =~ /Notification handle = 0x0421 value: (.*)/) {
|
||||||
return "$name|$mac|ok|$workType|$handle|$value|$1";
|
return "$name|$mac|ok|$workType|$handle|$value|$1";
|
||||||
} else {
|
} else {
|
||||||
if(defined($listen) && $listen eq "listen") {
|
if(defined($listen) and $listen eq "listen") {
|
||||||
return "$name|$mac|error|$workType|$handle|$value|notification missing";
|
return "$name|$mac|error|$workType|$handle|$value|notification missing";
|
||||||
} else {
|
} else {
|
||||||
return "$name|$mac|ok|$workType|$handle|$value";
|
return "$name|$mac|ok|$workType|$handle|$value";
|
||||||
@ -751,7 +758,7 @@ sub EQ3BT_setChildlock($$) {
|
|||||||
my $data = "01";
|
my $data = "01";
|
||||||
$data = "00" if($onoff eq "off");
|
$data = "00" if($onoff eq "off");
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setChildlock|0x0411|80".$data, "EQ3BT_processGatttoolResult", 60, "EQ3BT_killGatttool", $hash);
|
$hash->{helper}{RUNNING_PID} = BlockingCall("EQ3BT_execGatttool", $name."|".$hash->{MAC}."|setChildlock|0x0411|80".$data, "EQ3BT_processGatttoolResult", 90, "EQ3BT_killGatttool", $hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,8 +816,8 @@ sub EQ3BT_Get($$) {
|
|||||||
<h3>EQ3BT</h3>
|
<h3>EQ3BT</h3>
|
||||||
<ul>
|
<ul>
|
||||||
EQ3BT is used to control a EQ3 Bluetooth Smart Radiator Thermostat<br><br>
|
EQ3BT is used to control a EQ3 Bluetooth Smart Radiator Thermostat<br><br>
|
||||||
<b>Note:</b> The bluez package is required to run this module. Please check if gatttool executable is available on your system.
|
<b>Note:</b> The bluez package is required to run this module. Please check if gatttool executable is available on your system.
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<a name="EQ3BTdefine" id="EQ3BTdefine"></a>
|
<a name="EQ3BTdefine" id="EQ3BTdefine"></a>
|
||||||
|
@ -35,7 +35,7 @@ use Time::HiRes qw(gettimeofday);
|
|||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use Blocking;
|
use Blocking;
|
||||||
|
|
||||||
my $version = "0.2.4";
|
my $version = "0.2.5";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -51,14 +51,14 @@ sub HOMBOT_Initialize($) {
|
|||||||
$hash->{FW_detailFn} = "HOMBOT_DetailFn";
|
$hash->{FW_detailFn} = "HOMBOT_DetailFn";
|
||||||
|
|
||||||
$hash->{AttrList} = "interval ".
|
$hash->{AttrList} = "interval ".
|
||||||
"disable:1 ".
|
"disable:1 ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach my $d(sort keys %{$modules{HOMBOT}{defptr}}) {
|
foreach my $d(sort keys %{$modules{HOMBOT}{defptr}}) {
|
||||||
my $hash = $modules{HOMBOT}{defptr}{$d};
|
my $hash = $modules{HOMBOT}{defptr}{$d};
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,56 +126,56 @@ sub HOMBOT_Attr(@) {
|
|||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
|
|
||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq "disable" ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" ) {
|
||||||
if( $attrVal eq "0" ) {
|
if( $attrVal eq "0" ) {
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
InternalTimer( gettimeofday()+2, "HOMBOT_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
InternalTimer( gettimeofday()+2, "HOMBOT_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
Log3 $name, 3, "HOMBOT ($name) - enabled";
|
Log3 $name, 3, "HOMBOT ($name) - enabled";
|
||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
Log3 $name, 3, "HOMBOT ($name) - disabled";
|
Log3 $name, 3, "HOMBOT ($name) - disabled";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
RemoveInternalTimer( $hash );
|
RemoveInternalTimer( $hash );
|
||||||
InternalTimer( gettimeofday()+2, "HOMBOT_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
InternalTimer( gettimeofday()+2, "HOMBOT_Get_stateRequest", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" );
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
Log3 $name, 3, "HOMBOT ($name) - enabled";
|
Log3 $name, 3, "HOMBOT ($name) - enabled";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if($cmd eq "set") {
|
if($cmd eq "set") {
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
Log3 $name, 3, "HOMBOT ($name) - $attrName : $attrVal";
|
Log3 $name, 3, "HOMBOT ($name) - $attrName : $attrVal";
|
||||||
}
|
}
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $attrName eq "interval" ) {
|
if( $attrName eq "interval" ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" ) {
|
||||||
if( $attrVal < 60 ) {
|
if( $attrVal < 60 ) {
|
||||||
Log3 $name, 3, "HOMBOT ($name) - interval too small, please use something > 60 (sec), default is 180 (sec)";
|
Log3 $name, 3, "HOMBOT ($name) - interval too small, please use something > 60 (sec), default is 180 (sec)";
|
||||||
return "interval too small, please use something > 60 (sec), default is 180 (sec)";
|
return "interval too small, please use something > 60 (sec), default is 180 (sec)";
|
||||||
} else {
|
} else {
|
||||||
$hash->{INTERVAL} = $attrVal;
|
$hash->{INTERVAL} = $attrVal;
|
||||||
Log3 $name, 3, "HOMBOT ($name) - set interval to $attrVal";
|
Log3 $name, 3, "HOMBOT ($name) - set interval to $attrVal";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
$hash->{INTERVAL} = 180;
|
$hash->{INTERVAL} = 180;
|
||||||
Log3 $name, 3, "HOMBOT ($name) - set interval to default";
|
Log3 $name, 3, "HOMBOT ($name) - set interval to default";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" ) {
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
Log3 $name, 3, "HOMBOT ($name) - $attrName : $attrVal";
|
Log3 $name, 3, "HOMBOT ($name) - $attrName : $attrVal";
|
||||||
}
|
}
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -229,16 +229,16 @@ sub HOMBOT_getStatusTXT($) {
|
|||||||
|
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 10,
|
timeout => 10,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
method => "GET",
|
method => "GET",
|
||||||
doTrigger => 1,
|
doTrigger => 1,
|
||||||
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
||||||
id => "statustxt",
|
id => "statustxt",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve status.txt Information: calling Host: $host";
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve status.txt Information: calling Host: $host";
|
||||||
}
|
}
|
||||||
@ -255,16 +255,16 @@ sub HOMBOT_getStatisticHTML($) {
|
|||||||
|
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 10,
|
timeout => 10,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
method => "GET",
|
method => "GET",
|
||||||
doTrigger => 1,
|
doTrigger => 1,
|
||||||
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
||||||
id => "statistichtml",
|
id => "statistichtml",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve statistic.html Information: calling Host: $host";
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve statistic.html Information: calling Host: $host";
|
||||||
}
|
}
|
||||||
@ -281,16 +281,16 @@ sub HOMBOT_getSchedule($) {
|
|||||||
|
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 10,
|
timeout => 10,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
method => "GET",
|
method => "GET",
|
||||||
doTrigger => 1,
|
doTrigger => 1,
|
||||||
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
callback => \&HOMBOT_RetrieveHomebotInfoFinished,
|
||||||
id => "schedule",
|
id => "schedule",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
Log3 $name, 4, "HOMBOT ($name) - NonblockingGet get URL";
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve Schedule Information: calling Host: $host";
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Retrieve Schedule Information: calling Host: $host";
|
||||||
}
|
}
|
||||||
@ -310,58 +310,59 @@ sub HOMBOT_RetrieveHomebotInfoFinished($$$) {
|
|||||||
|
|
||||||
### Begin Error Handling
|
### Begin Error Handling
|
||||||
if( $hash->{helper}{requestErrorCounter} > 1 ) {
|
if( $hash->{helper}{requestErrorCounter} > 1 ) {
|
||||||
|
|
||||||
readingsSingleUpdate( $hash, "lastStatusRequestState", "statusRequest_error", 1 );
|
readingsSingleUpdate( $hash, "lastStatusRequestState", "statusRequest_error", 1 );
|
||||||
|
|
||||||
|
if( $hash->{helper}{requestErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
|
||||||
if( $hash->{helper}{requestErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
|
|
||||||
|
Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
|
||||||
Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
|
|
||||||
|
$hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|request", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|request", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBeginUpdate( $hash );
|
|
||||||
|
|
||||||
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "unknown error, please contact the developer" );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
|
|
||||||
|
|
||||||
$attr{$name}{disable} = 1;
|
|
||||||
readingsBulkUpdate ( $hash, "state", "Unknown Error, device disabled");
|
|
||||||
|
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
|
||||||
$hash->{helper}{setErrorCounter} = 0;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} == 0 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "Homebot is offline" );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Homebot is offline";
|
|
||||||
|
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
|
||||||
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
|
||||||
|
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
|
||||||
$hash->{helper}{setErrorCounter} = 0;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 0 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "to many errors, check your network configuration" );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - To many Errors please check your Network Configuration";
|
|
||||||
|
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
||||||
readingsBulkUpdate ( $hash, "state", "To many Errors");
|
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "unknown error, please contact the developer" );
|
||||||
}
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
Log3 $name, 4, "HOMBOT ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
|
||||||
|
|
||||||
|
$attr{$name}{disable} = 1;
|
||||||
|
readingsBulkUpdate ( $hash, "state", "Unknown Error, device disabled");
|
||||||
|
|
||||||
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
|
$hash->{helper}{setErrorCounter} = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} == 0 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
||||||
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "Homebot is offline" );
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - Homebot is offline";
|
||||||
|
|
||||||
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
|
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
||||||
|
|
||||||
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
|
$hash->{helper}{setErrorCounter} = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 0 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
||||||
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "to many errors, check your network configuration" );
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - To many Errors please check your Network Configuration";
|
||||||
|
|
||||||
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
|
readingsBulkUpdate ( $hash, "state", "To many Errors");
|
||||||
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( defined( $err ) && $err ne "" ) {
|
if( defined( $err ) && $err ne "" ) {
|
||||||
@ -373,49 +374,49 @@ sub HOMBOT_RetrieveHomebotInfoFinished($$$) {
|
|||||||
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
||||||
readingsBulkUpdate($hash, "lastStatusRequestError", $err );
|
readingsBulkUpdate($hash, "lastStatusRequestError", $err );
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Parse_HomebotInfomations: error while request: $err";
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Parse_HomebotInfomations: error while request: $err";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $data eq "" and exists( $param->{code} ) ) {
|
elsif( $data eq "" and exists( $param->{code} ) ) {
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate ( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 1 ) ne "initialized" );
|
readingsBulkUpdate ( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 1 ) ne "initialized" );
|
||||||
$hash->{helper}{requestErrorCounter} = ( $hash->{helper}{requestErrorCounter} + 1 );
|
$hash->{helper}{requestErrorCounter} = ( $hash->{helper}{requestErrorCounter} + 1 );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
||||||
|
|
||||||
if( $param->{code} ne 200 ) {
|
if( $param->{code} ne 200 ) {
|
||||||
readingsBulkUpdate( $hash," lastStatusRequestError", "http Error ".$param->{code} );
|
readingsBulkUpdate( $hash," lastStatusRequestError", "http Error ".$param->{code} );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "empty response" );
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_RetrieveHomebotInfomationsFinished: received http code ".$param->{code}." without any data after requesting HOMBOT Device";
|
|
||||||
|
|
||||||
return;
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "empty response" );
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_RetrieveHomebotInfomationsFinished: received http code ".$param->{code}." without any data after requesting HOMBOT Device";
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
|
elsif( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state" ,0) ne "initialized" );
|
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state" ,0) ne "initialized" );
|
||||||
$hash->{helper}{requestErrorCounter} = ( $hash->{helper}{requestErrorCounter} + 1 );
|
$hash->{helper}{requestErrorCounter} = ( $hash->{helper}{requestErrorCounter} + 1 );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" );
|
||||||
|
|
||||||
if( $param->{code} eq 404 ) {
|
if( $param->{code} eq 404 ) {
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "HTTP Server at Homebot offline" );
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "HTTP Server at Homebot offline" );
|
||||||
} else {
|
} else {
|
||||||
readingsBulkUpdate( $hash, "lastStatusRequestError", "http error ".$param->{code} );
|
readingsBulkUpdate( $hash, "lastStatusRequestError", "http error ".$param->{code} );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Parse_HomebotInfomations: received http code ".$param->{code}." receive Error after requesting HOMBOT";
|
|
||||||
|
|
||||||
return;
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - HOMBOT_Parse_HomebotInfomations: received http code ".$param->{code}." receive Error after requesting HOMBOT";
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
### End Error Handling
|
### End Error Handling
|
||||||
@ -552,42 +553,42 @@ sub HOMBOT_Set($$@) {
|
|||||||
my ( $hash, $name, $cmd, @val ) = @_;
|
my ( $hash, $name, $cmd, @val ) = @_;
|
||||||
|
|
||||||
|
|
||||||
my $list = "";
|
my $list = "";
|
||||||
$list .= "cleanStart:noArg ";
|
$list .= "cleanStart:noArg ";
|
||||||
$list .= "homing:noArg ";
|
$list .= "homing:noArg ";
|
||||||
$list .= "pause:noArg ";
|
$list .= "pause:noArg ";
|
||||||
$list .= "statusRequest:noArg ";
|
$list .= "statusRequest:noArg ";
|
||||||
$list .= "cleanMode:SB,ZZ,SPOT ";
|
$list .= "cleanMode:SB,ZZ,SPOT ";
|
||||||
$list .= "repeat:true,false ";
|
$list .= "repeat:true,false ";
|
||||||
$list .= "turbo:true,false ";
|
$list .= "turbo:true,false ";
|
||||||
$list .= "nickname ";
|
$list .= "nickname ";
|
||||||
$list .= "schedule ";
|
$list .= "schedule ";
|
||||||
|
|
||||||
|
|
||||||
if( lc $cmd eq 'cleanstart'
|
|
||||||
|| lc $cmd eq 'homing'
|
|
||||||
|| lc $cmd eq 'pause'
|
|
||||||
|| lc $cmd eq 'statusrequest'
|
|
||||||
|| lc $cmd eq 'cleanmode'
|
|
||||||
|| lc $cmd eq 'repeat'
|
|
||||||
|| lc $cmd eq 'turbo'
|
|
||||||
|| lc $cmd eq 'nickname'
|
|
||||||
|| lc $cmd eq 'schedule' ) {
|
|
||||||
|
|
||||||
Log3 $name, 5, "HOMBOT ($name) - set $name $cmd ".join(" ", @val);
|
|
||||||
|
|
||||||
|
|
||||||
my $val = join( " ", @val );
|
if( lc $cmd eq 'cleanstart'
|
||||||
my $wordlenght = length($val);
|
|| lc $cmd eq 'homing'
|
||||||
|
|| lc $cmd eq 'pause'
|
||||||
|
|| lc $cmd eq 'statusrequest'
|
||||||
|
|| lc $cmd eq 'cleanmode'
|
||||||
|
|| lc $cmd eq 'repeat'
|
||||||
|
|| lc $cmd eq 'turbo'
|
||||||
|
|| lc $cmd eq 'nickname'
|
||||||
|
|| lc $cmd eq 'schedule' ) {
|
||||||
|
|
||||||
return HOMBOT_SelectSetCmd( $hash, $cmd, @val ) if( lc $cmd eq 'statusrequest' );
|
Log3 $name, 5, "HOMBOT ($name) - set $name $cmd ".join(" ", @val);
|
||||||
return "set command only works if state not equal initialized, please wait for next interval run" if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "initialized");
|
|
||||||
return "to many character for Nickname" if(( $wordlenght < 2 || $wordlenght > 16 ) && lc $cmd eq 'nickname' );
|
|
||||||
|
|
||||||
return HOMBOT_SelectSetCmd( $hash, $cmd, @val ) if( ( ( @val ) || lc $cmd eq 'cleanstart'|| lc $cmd eq 'homing' || lc $cmd eq 'pause' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Unknown argument $cmd, bearword as argument or wrong parameter(s), choose one of $list";
|
my $val = join( " ", @val );
|
||||||
|
my $wordlenght = length($val);
|
||||||
|
|
||||||
|
return HOMBOT_SelectSetCmd( $hash, $cmd, @val ) if( lc $cmd eq 'statusrequest' );
|
||||||
|
return "set command only works if state not equal initialized, please wait for next interval run" if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "initialized");
|
||||||
|
return "to many character for Nickname" if(( $wordlenght < 2 || $wordlenght > 16 ) && lc $cmd eq 'nickname' );
|
||||||
|
|
||||||
|
return HOMBOT_SelectSetCmd( $hash, $cmd, @val ) if( ( ( @val ) || lc $cmd eq 'cleanstart'|| lc $cmd eq 'homing' || lc $cmd eq 'pause' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown argument $cmd, bearword as argument or wrong parameter(s), choose one of $list";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub HOMBOT_SelectSetCmd($$@) {
|
sub HOMBOT_SelectSetCmd($$@) {
|
||||||
@ -598,75 +599,75 @@ sub HOMBOT_SelectSetCmd($$@) {
|
|||||||
my $port = $hash->{PORT};
|
my $port = $hash->{PORT};
|
||||||
|
|
||||||
if( lc $cmd eq 'cleanstart' ) {
|
if( lc $cmd eq 'cleanstart' ) {
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22CLEAN_START%22%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Homebot start cleaning";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22CLEAN_START%22%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - Homebot start cleaning";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'homing' ) {
|
elsif( lc $cmd eq 'homing' ) {
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22HOMING%22%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Homebot come home";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22HOMING%22%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - Homebot come home";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'pause' ) {
|
elsif( lc $cmd eq 'pause' ) {
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22PAUSE%22%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Homebot paused";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%22PAUSE%22%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - Homebot paused";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'cleanmode' ) {
|
elsif( lc $cmd eq 'cleanmode' ) {
|
||||||
my $mode = join( " ", @data );
|
my $mode = join( " ", @data );
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22CLEAN_MODE%22:%22CLEAN_".$mode."%22%7d%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - set Cleanmode to $mode";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22CLEAN_MODE%22:%22CLEAN_".$mode."%22%7d%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - set Cleanmode to $mode";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'statusrequest' ) {
|
elsif( lc $cmd eq 'statusrequest' ) {
|
||||||
HOMBOT_Get_stateRequestLocal( $hash );
|
HOMBOT_Get_stateRequestLocal( $hash );
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'repeat' ) {
|
elsif( lc $cmd eq 'repeat' ) {
|
||||||
my $repeat = join( " ", @data );
|
my $repeat = join( " ", @data );
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22REPEAT%22:%22".$repeat."%22%7d%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - set Repeat to $repeat";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22REPEAT%22:%22".$repeat."%22%7d%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - set Repeat to $repeat";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'turbo' ) {
|
elsif( lc $cmd eq 'turbo' ) {
|
||||||
my $turbo = join( " ", @data );
|
my $turbo = join( " ", @data );
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22TURBO%22:%22".$turbo."%22%7d%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - set Turbo to $turbo";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22COMMAND%22:%7b%22TURBO%22:%22".$turbo."%22%7d%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - set Turbo to $turbo";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'nickname' ) {
|
elsif( lc $cmd eq 'nickname' ) {
|
||||||
my $nick = join( " ", @data );
|
my $nick = join( " ", @data );
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22NICKNAME%22:%7b%22SET%22:%22".$nick."%22%7d%7d";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - set Nickname to $nick";
|
my $url = "http://" . $host . ":" . $port . "/json.cgi?%7b%22NICKNAME%22:%7b%22SET%22:%22".$nick."%22%7d%7d";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - set Nickname to $nick";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'schedule' ) {
|
elsif( lc $cmd eq 'schedule' ) {
|
||||||
@ -685,12 +686,12 @@ sub HOMBOT_SelectSetCmd($$@) {
|
|||||||
$data[5] =~ s/Sa/SATURDAY/g;
|
$data[5] =~ s/Sa/SATURDAY/g;
|
||||||
#my $su = $data[6];
|
#my $su = $data[6];
|
||||||
$data[6] =~ s/So/SUNDAY/g;
|
$data[6] =~ s/So/SUNDAY/g;
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/sites/schedule.html?".$data[0]."&".$data[1]."&".$data[2]."&".$data[3]."&".$data[4]."&".$data[5]."&".$data[6]."&SEND=Save";
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - set schedule to $data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6]";
|
my $url = "http://" . $host . ":" . $port . "/sites/schedule.html?".$data[0]."&".$data[1]."&".$data[2]."&".$data[3]."&".$data[4]."&".$data[5]."&".$data[6]."&SEND=Save";
|
||||||
|
|
||||||
return HOMBOT_HTTP_POST( $hash,$url );
|
Log3 $name, 4, "HOMBOT ($name) - set schedule to $data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6]";
|
||||||
|
|
||||||
|
return HOMBOT_HTTP_POST( $hash,$url );
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -706,15 +707,15 @@ sub HOMBOT_HTTP_POST($$) {
|
|||||||
readingsSingleUpdate( $hash, "state", "Send HTTP POST", 1 );
|
readingsSingleUpdate( $hash, "state", "Send HTTP POST", 1 );
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 10,
|
timeout => 10,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
method => "GET",
|
method => "GET",
|
||||||
doTrigger => 1,
|
doTrigger => 1,
|
||||||
callback => \&HOMBOT_HTTP_POSTerrorHandling,
|
callback => \&HOMBOT_HTTP_POSTerrorHandling,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Send HTTP POST with URL $url";
|
Log3 $name, 4, "HOMBOT ($name) - Send HTTP POST with URL $url";
|
||||||
|
|
||||||
readingsSingleUpdate( $hash, "state", $state, 1 );
|
readingsSingleUpdate( $hash, "state", $state, 1 );
|
||||||
@ -731,102 +732,103 @@ sub HOMBOT_HTTP_POSTerrorHandling($$$) {
|
|||||||
|
|
||||||
### Begin Error Handling
|
### Begin Error Handling
|
||||||
if( $hash->{helper}{setErrorCounter} > 1 ) {
|
if( $hash->{helper}{setErrorCounter} > 1 ) {
|
||||||
|
|
||||||
readingsSingleUpdate( $hash, "lastSetCommandState", "statusRequest_error", 1 );
|
readingsSingleUpdate( $hash, "lastSetCommandState", "statusRequest_error", 1 );
|
||||||
|
|
||||||
|
|
||||||
if( $hash->{helper}{setErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
|
if( $hash->{helper}{setErrorCounter} > 1 && ReadingsVal( $name, "luigiHttpSrvState", "not running" ) eq "running" ) {
|
||||||
|
|
||||||
Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
|
Log3 $name, 3, "HOMBOT ($name) - Connecting Problem, will check Luigi HTTP Server" unless(exists($hash->{helper}{RUNNING_PID}));
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|set", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
$hash->{helper}{RUNNING_PID} = BlockingCall("HOMBOT_Check_Bot_Alive", $name."|set", "HOMBOT_Evaluation_Bot_Alive", 15, "HOMBOT_Aborted_Bot_Alive", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
|
|
||||||
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 2 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
|
||||||
readingsBulkUpdate($hash, "lastSetCommandError", "unknown error, please contact the developer" );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
|
|
||||||
|
|
||||||
$attr{$name}{disable} = 1;
|
|
||||||
readingsBulkUpdate( $hash, "state", "Unknown Error" );
|
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
|
||||||
$hash->{helper}{setErrorCounter} = 0;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif( $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "not running" ){
|
if( $hash->{helper}{requestErrorCounter} > 6 && $hash->{helper}{setErrorCounter} > 2 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandError", "HTTP Server at Homebot offline" );
|
readingsBulkUpdate($hash, "lastSetCommandError", "unknown error, please contact the developer" );
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - Please check HTTP Server at Homebot";
|
|
||||||
|
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
|
||||||
$hash->{helper}{setErrorCounter} = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif( $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandError", "to many errors, check your network or device configuration" );
|
|
||||||
|
|
||||||
Log3 $name, 4, "HOMBOT ($name) - To many Errors please check your Network or Device Configuration";
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "state", "To many Errors" );
|
Log3 $name, 4, "HOMBOT ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
|
||||||
|
$attr{$name}{disable} = 1;
|
||||||
$hash->{helper}{setErrorCounter} = 0;
|
readingsBulkUpdate( $hash, "state", "Unknown Error" );
|
||||||
$hash->{helper}{requestErrorCounter} = 0;
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
}
|
$hash->{helper}{setErrorCounter} = 0;
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif( $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "not running" ){
|
||||||
|
readingsBulkUpdate( $hash, "lastSetCommandError", "HTTP Server at Homebot offline" );
|
||||||
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - Please check HTTP Server at Homebot";
|
||||||
|
|
||||||
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
|
$hash->{helper}{setErrorCounter} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif( $hash->{helper}{setErrorCounter} > 3 && ReadingsVal( $name, "luigiHttpSrvState", "running" ) eq "running" ) {
|
||||||
|
readingsBulkUpdate( $hash, "lastSetCommandError", "to many errors, check your network or device configuration" );
|
||||||
|
|
||||||
|
Log3 $name, 4, "HOMBOT ($name) - To many Errors please check your Network or Device Configuration";
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "state", "To many Errors" );
|
||||||
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
|
|
||||||
|
$hash->{helper}{setErrorCounter} = 0;
|
||||||
|
$hash->{helper}{requestErrorCounter} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( defined( $err ) && $err ne "" ) {
|
if( defined( $err ) && $err ne "" ) {
|
||||||
|
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate( $hash, "state", $err ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" );
|
readingsBulkUpdate( $hash, "state", $err ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" );
|
||||||
$hash->{helper}{setErrorCounter} = ($hash->{helper}{setErrorCounter} + 1);
|
$hash->{helper}{setErrorCounter} = ($hash->{helper}{setErrorCounter} + 1);
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" );
|
readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" );
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandError", "$err" );
|
readingsBulkUpdate( $hash, "lastSetCommandError", "$err" );
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
Log3 $name, 5, "HOMBOT ($name) - HOMBOT_HTTP_POST: error while POST Command: $err";
|
Log3 $name, 5, "HOMBOT ($name) - HOMBOT_HTTP_POST: error while POST Command: $err";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
|
if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $hash, "state", 0 ) ne "initialized" );
|
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $hash, "state", 0 ) ne "initialized" );
|
||||||
|
|
||||||
$hash->{helper}{setErrorCounter} = ( $hash->{helper}{setErrorCounter} + 1 );
|
|
||||||
|
|
||||||
readingsBulkUpdate($hash, "lastSetCommandState", "cmd_error" );
|
$hash->{helper}{setErrorCounter} = ( $hash->{helper}{setErrorCounter} + 1 );
|
||||||
readingsBulkUpdate($hash, "lastSetCommandError", "http Error ".$param->{code} );
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
|
||||||
|
|
||||||
Log3 $name, 5, "HOMBOT ($name) - HOMBOT_HTTP_POST: received http code ".$param->{code};
|
|
||||||
|
|
||||||
return;
|
readingsBulkUpdate($hash, "lastSetCommandState", "cmd_error" );
|
||||||
|
readingsBulkUpdate($hash, "lastSetCommandError", "http Error ".$param->{code} );
|
||||||
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
Log3 $name, 5, "HOMBOT ($name) - HOMBOT_HTTP_POST: received http code ".$param->{code};
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
|
if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
|
||||||
readingsBeginUpdate( $hash );
|
readingsBeginUpdate( $hash );
|
||||||
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" );
|
readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" );
|
||||||
|
|
||||||
$hash->{helper}{setErrorCounter} = ( $hash->{helper}{setErrorCounter} + 1 );
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" );
|
$hash->{helper}{setErrorCounter} = ( $hash->{helper}{setErrorCounter} + 1 );
|
||||||
|
|
||||||
|
readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" );
|
||||||
|
|
||||||
if( $param->{code} eq 404 ) {
|
if( $param->{code} eq 404 ) {
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandError", "HTTP Server at Homebot is offline!" );
|
readingsBulkUpdate( $hash, "lastSetCommandError", "HTTP Server at Homebot is offline!" );
|
||||||
} else {
|
} else {
|
||||||
readingsBulkUpdate( $hash, "lastSetCommandError", "http error ".$param->{code} );
|
readingsBulkUpdate( $hash, "lastSetCommandError", "http error ".$param->{code} );
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
### End Error Handling
|
### End Error Handling
|
||||||
@ -923,7 +925,7 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
|
|||||||
|
|
||||||
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
|
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
||||||
|
|
||||||
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
|
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
|
||||||
}
|
}
|
||||||
@ -958,7 +960,7 @@ sub HOMBOT_Evaluation_Bot_Alive($) {
|
|||||||
|
|
||||||
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
|
readingsBulkUpdate( $hash, "luigiHttpSrvState", "running");
|
||||||
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
readingsBulkUpdate ( $hash, "hombotState", "OFFLINE");
|
||||||
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
readingsBulkUpdate ( $hash, "state", "Homebot offline");
|
||||||
|
|
||||||
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
|
Log3 $name, 3, "HOMBOT ($name) - Hombot is not online";
|
||||||
}
|
}
|
||||||
@ -995,6 +997,8 @@ sub HOMBOT_DetailFn() { # Patch von Andre (justme1968)
|
|||||||
|
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
=item summary connection to LG Homebot robotic vacuum cleaner
|
||||||
|
=item summary_DE Anbindung LG Homebot Staubsaugerroboter
|
||||||
=begin html
|
=begin html
|
||||||
|
|
||||||
<a name="HOMBOT"></a>
|
<a name="HOMBOT"></a>
|
||||||
@ -1158,4 +1162,4 @@ sub HOMBOT_DetailFn() { # Patch von Andre (justme1968)
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
=end html_DE
|
=end html_DE
|
||||||
=cut
|
=cut
|
||||||
|
Loading…
Reference in New Issue
Block a user