mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
70_BOTVAC.pm: use keepalive for status update; refactor connection handling; fix warnings while loading maps
git-svn-id: https://svn.fhem.de/fhem/trunk@21471 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
086e2c5b1c
commit
e67405e9cd
@ -1,5 +1,8 @@
|
|||||||
# 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.
|
||||||
|
- change: 70_BOTVAC: use keepalive for status update
|
||||||
|
refactor connection handling
|
||||||
|
fix warnings while loading maps
|
||||||
- feature: speechrecogn.template: Add logic to set alexa- and siriName
|
- feature: speechrecogn.template: Add logic to set alexa- and siriName
|
||||||
mqtt2.template: change speech recogn. logics at tasmota
|
mqtt2.template: change speech recogn. logics at tasmota
|
||||||
- feature: 93_DbRep: older than days / newer than days for reduceLog
|
- feature: 93_DbRep: older than days / newer than days for reduceLog
|
||||||
|
@ -45,6 +45,7 @@ sub BOTVAC_Initialize($) {
|
|||||||
$hash->{AttrList} = "disable:0,1 " .
|
$hash->{AttrList} = "disable:0,1 " .
|
||||||
"actionInterval " .
|
"actionInterval " .
|
||||||
"boundaries:textField-long " .
|
"boundaries:textField-long " .
|
||||||
|
"sslVerify:0,1 " .
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,6 @@ use GPUtils qw(:all); # wird für den Import der FHEM Funktionen aus der fhem.p
|
|||||||
|
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use JSON qw(decode_json encode_json);
|
use JSON qw(decode_json encode_json);
|
||||||
#use IO::Socket::SSL::Utils qw(PEM_string2cert);
|
|
||||||
use Digest::SHA qw(hmac_sha256_hex sha1_hex);
|
use Digest::SHA qw(hmac_sha256_hex sha1_hex);
|
||||||
use Encode qw(encode_utf8);
|
use Encode qw(encode_utf8);
|
||||||
use MIME::Base64;
|
use MIME::Base64;
|
||||||
@ -665,17 +665,16 @@ sub SendCommand($$;$$@) {
|
|||||||
my $password = ReadPassword($hash);
|
my $password = ReadPassword($hash);
|
||||||
my $timestamp = gettimeofday();
|
my $timestamp = gettimeofday();
|
||||||
my $timeout = 180;
|
my $timeout = 180;
|
||||||
my $header;
|
my $keepalive = 0;
|
||||||
my $data;
|
|
||||||
my $reqId = 0;
|
my $reqId = 0;
|
||||||
|
|
||||||
Log3($name, 5, "BOTVAC $name: called function SendCommand()");
|
|
||||||
|
|
||||||
my $URL = "https://";
|
my $URL = "https://";
|
||||||
|
my %sslArgs = {};
|
||||||
|
my %header;
|
||||||
|
my $data;
|
||||||
my $response;
|
my $response;
|
||||||
my $return;
|
my $return;
|
||||||
|
|
||||||
my %sslArgs;
|
Log3($name, 5, "BOTVAC $name: called function SendCommand()");
|
||||||
|
|
||||||
if ($service ne "sessions" && $service ne "dashboard") {
|
if ($service ne "sessions" && $service ne "dashboard") {
|
||||||
return if (CheckRegistration($hash, $service, $cmd, $option, @successor));
|
return if (CheckRegistration($hash, $service, $cmd, $option, @successor));
|
||||||
@ -690,8 +689,20 @@ sub SendCommand($$;$$@) {
|
|||||||
Log3($name, 4, "BOTVAC $name: REQ option $option") if (defined($option));
|
Log3($name, 4, "BOTVAC $name: REQ option $option") if (defined($option));
|
||||||
LogSuccessors($hash, @successor);
|
LogSuccessors($hash, @successor);
|
||||||
|
|
||||||
$header = "Accept: application/vnd.neato.nucleo.v1";
|
$header{Accept} = "application/vnd.neato.nucleo.v1";
|
||||||
$header .= "\r\nContent-Type: application/json";
|
$header{'Content-Type'} = "application/json";
|
||||||
|
|
||||||
|
my $sslVerify= AttrVal($name, "sslVerify", undef);
|
||||||
|
if(defined($sslVerify)) {
|
||||||
|
eval "use IO::Socket::SSL";
|
||||||
|
if($@) {
|
||||||
|
Log3($name, 2, $@);
|
||||||
|
} else {
|
||||||
|
my $sslVerifyMode= eval("$sslVerify ? SSL_VERIFY_PEER : SSL_VERIFY_NONE");
|
||||||
|
Log3($name, 5, "SSL verify mode set to $sslVerifyMode");
|
||||||
|
$sslArgs{SSL_verify_mode} = $sslVerifyMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($service eq "sessions") {
|
if ($service eq "sessions") {
|
||||||
if (!defined($password)) {
|
if (!defined($password)) {
|
||||||
@ -702,23 +713,20 @@ sub SendCommand($$;$$@) {
|
|||||||
$URL .= GetBeehiveHost($hash->{VENDOR});
|
$URL .= GetBeehiveHost($hash->{VENDOR});
|
||||||
$URL .= "/sessions";
|
$URL .= "/sessions";
|
||||||
$data = "{\"platform\": \"ios\", \"email\": \"$email\", \"token\": \"$token\", \"password\": \"$password\"}";
|
$data = "{\"platform\": \"ios\", \"email\": \"$email\", \"token\": \"$token\", \"password\": \"$password\"}";
|
||||||
%sslArgs = ( SSL_verify_mode => 0 );
|
|
||||||
|
|
||||||
} elsif ($service eq "dashboard") {
|
} elsif ($service eq "dashboard") {
|
||||||
$header .= "\r\nAuthorization: Token token=".ReadingsVal($name, ".accessToken", "");
|
$header{Authorization} = "Token token=".ReadingsVal($name, ".accessToken", "");
|
||||||
$URL .= GetBeehiveHost($hash->{VENDOR});
|
$URL .= GetBeehiveHost($hash->{VENDOR});
|
||||||
$URL .= "/dashboard";
|
$URL .= "/dashboard";
|
||||||
%sslArgs = ( SSL_verify_mode => 0 );
|
|
||||||
|
|
||||||
} elsif ($service eq "robots") {
|
} elsif ($service eq "robots") {
|
||||||
my $serial = ReadingsVal($name, "serial", "");
|
my $serial = ReadingsVal($name, "serial", "");
|
||||||
return if ($serial eq "");
|
return if ($serial eq "");
|
||||||
|
|
||||||
$header .= "\r\nAuthorization: Token token=".ReadingsVal($name, ".accessToken", "");
|
$header{Authorization} = "Token token=".ReadingsVal($name, ".accessToken", "");
|
||||||
$URL .= GetBeehiveHost($hash->{VENDOR});
|
$URL .= GetBeehiveHost($hash->{VENDOR});
|
||||||
$URL .= "/users/me/robots/$serial/";
|
$URL .= "/users/me/robots/$serial/";
|
||||||
$URL .= (defined($cmd) ? $cmd : "maps");
|
$URL .= (defined($cmd) ? $cmd : "maps");
|
||||||
%sslArgs = ( SSL_verify_mode => 0 );
|
|
||||||
|
|
||||||
} elsif ($service eq "messages") {
|
} elsif ($service eq "messages") {
|
||||||
my $serial = ReadingsVal($name, "serial", "");
|
my $serial = ReadingsVal($name, "serial", "");
|
||||||
@ -814,11 +822,10 @@ sub SendCommand($$;$$@) {
|
|||||||
my $message = join("\n", (lc($serial), $date, $data));
|
my $message = join("\n", (lc($serial), $date, $data));
|
||||||
my $hmac = hmac_sha256_hex($message, ReadingsVal($name, ".secretKey", ""));
|
my $hmac = hmac_sha256_hex($message, ReadingsVal($name, ".secretKey", ""));
|
||||||
|
|
||||||
$header .= "\r\nDate: $date";
|
$header{Date} = $date;
|
||||||
$header .= "\r\nAuthorization: NEATOAPP $hmac";
|
$header{Authorization} = "NEATOAPP $hmac";
|
||||||
|
$keepalive = 1;
|
||||||
|
|
||||||
#%sslArgs = ( SSL_ca => [ GetCAKey( $hash ) ] );
|
|
||||||
%sslArgs = ( SSL_verify_mode => 0 );
|
|
||||||
} elsif ($service eq "loadmap") {
|
} elsif ($service eq "loadmap") {
|
||||||
$URL = $cmd;
|
$URL = $cmd;
|
||||||
}
|
}
|
||||||
@ -828,25 +835,31 @@ sub SendCommand($$;$$@) {
|
|||||||
if ( defined($data) );
|
if ( defined($data) );
|
||||||
Log3($name, 5, "BOTVAC $name: GET $URL")
|
Log3($name, 5, "BOTVAC $name: GET $URL")
|
||||||
if ( !defined($data) );
|
if ( !defined($data) );
|
||||||
Log3($name, 5, "BOTVAC $name: header $header")
|
Log3($name, 5, "BOTVAC $name: header ".join("\n", map(($_.': '.$header{$_}), keys %header)))
|
||||||
if ( defined($header) );
|
if ( %header );
|
||||||
|
|
||||||
::HttpUtils_NonblockingGet(
|
my $params = {
|
||||||
{
|
|
||||||
url => $URL,
|
url => $URL,
|
||||||
timeout => $timeout,
|
timeout => $timeout,
|
||||||
noshutdown => 1,
|
noshutdown => 1,
|
||||||
header => $header,
|
keepalive => $keepalive,
|
||||||
|
header => \%header,
|
||||||
data => $data,
|
data => $data,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
service => $service,
|
service => $service,
|
||||||
cmd => $cmd,
|
cmd => $cmd,
|
||||||
successor => \@successor,
|
successor => \@successor,
|
||||||
timestamp => $timestamp,
|
timestamp => $timestamp,
|
||||||
sslargs => { %sslArgs },
|
sslargs => \%sslArgs,
|
||||||
callback => \&ReceiveCommand,
|
callback => \&ReceiveCommand
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($keepalive) {
|
||||||
|
map {$hash->{helper}{".HTTP_CONNECTION"}{$_} = $params->{$_}} keys %{$params};
|
||||||
|
::HttpUtils_NonblockingGet($hash->{helper}{".HTTP_CONNECTION"});
|
||||||
|
} else {
|
||||||
|
::HttpUtils_NonblockingGet($params);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -858,6 +871,9 @@ sub ReceiveCommand($$$) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $service = $param->{service};
|
my $service = $param->{service};
|
||||||
my $cmd = $param->{cmd};
|
my $cmd = $param->{cmd};
|
||||||
|
my $url = $param->{url};
|
||||||
|
my $keepalive = $param->{keepalive};
|
||||||
|
my $respHeader = $param->{httpheader};
|
||||||
my @successor = @{$param->{successor}};
|
my @successor = @{$param->{successor}};
|
||||||
|
|
||||||
my $rc = ( $param->{buf} ) ? $param->{buf} : $param;
|
my $rc = ( $param->{buf} ) ? $param->{buf} : $param;
|
||||||
@ -865,8 +881,10 @@ sub ReceiveCommand($$$) {
|
|||||||
my $loadMap;
|
my $loadMap;
|
||||||
my $return;
|
my $return;
|
||||||
my $reqId = 0;
|
my $reqId = 0;
|
||||||
|
my $closeConnection = ($respHeader =~ m/.*[Cc]onnection: keep-alive.*/ ? 0 : 1);
|
||||||
|
|
||||||
Log3($name, 5, "BOTVAC $name: called function ReceiveCommand() rc: $rc err: $err data: $data ");
|
Log3($name, 5, "BOTVAC $name: called function ReceiveCommand() rc: $rc err: $err data: $data ");
|
||||||
|
Log3($name, 5, "BOTVAC $name: http header: $respHeader") if (defined($respHeader));
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
@ -1224,8 +1242,8 @@ sub ReceiveCommand($$$) {
|
|||||||
my $t2 = GetSecondsFromString($map->{start_at});
|
my $t2 = GetSecondsFromString($map->{start_at});
|
||||||
my $dt = $t1-$t2-$map->{time_in_suspended_cleaning}-$map->{time_in_error}-$map->{time_in_pause};
|
my $dt = $t1-$t2-$map->{time_in_suspended_cleaning}-$map->{time_in_error}-$map->{time_in_pause};
|
||||||
my $dc = $map->{run_charge_at_start}-$map->{run_charge_at_end};
|
my $dc = $map->{run_charge_at_start}-$map->{run_charge_at_end};
|
||||||
my $expa = int($map->{cleaned_area}*100/$dc+.5) if ($dc > 0);
|
my $expa = $dc>0?int($map->{cleaned_area}*100/$dc+.5):0;
|
||||||
my $expt = int($dt*100/$dc/60+.5) if ($dc > 0);
|
my $expt = $dc>0?int($dt*100/$dc/60+.5):0;
|
||||||
readingsBulkUpdateIfChanged($hash, "map_duration", int($dt/6+.5)/10); # min
|
readingsBulkUpdateIfChanged($hash, "map_duration", int($dt/6+.5)/10); # min
|
||||||
readingsBulkUpdateIfChanged($hash, "map_expected_area", $expa>0?$expa:0); # qm
|
readingsBulkUpdateIfChanged($hash, "map_expected_area", $expa>0?$expa:0); # qm
|
||||||
readingsBulkUpdateIfChanged($hash, "map_run_discharge", $dc>0?$dc:0); # %
|
readingsBulkUpdateIfChanged($hash, "map_run_discharge", $dc>0?$dc:0); # %
|
||||||
@ -1273,9 +1291,16 @@ sub ReceiveCommand($$$) {
|
|||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
|
if (defined($hash->{helper}{".HTTP_CONNECTION"}) and
|
||||||
|
(($keepalive and $closeConnection) or !@successor)) {
|
||||||
|
Log3($name, 4, "BOTVAC $name: Close connection");
|
||||||
|
::HttpUtils_Close($hash->{helper}{".HTTP_CONNECTION"});
|
||||||
|
undef($hash->{helper}{".HTTP_CONNECTION"});
|
||||||
|
}
|
||||||
|
|
||||||
if ($loadMap) {
|
if ($loadMap) {
|
||||||
my $url = ReadingsVal($name, ".map_url", "");
|
my $mapurl = ReadingsVal($name, ".map_url", "");
|
||||||
push(@successor , ["loadmap", $url]) if ($url ne "");
|
push(@successor , ["loadmap", $mapurl]) if ($mapurl ne "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@successor) {
|
if (@successor) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user