2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-17 05:16:02 +00:00

70_VolumeLink: Added fast-retry of 0.1 sec for the first 3 timeouts.

git-svn-id: https://svn.fhem.de/fhem/trunk@9088 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rapster 2015-08-17 21:09:20 +00:00
parent eac0c17903
commit b8b2e9ffb2

View File

@ -56,14 +56,16 @@ sub VolumeLink_Define($$) {
ampMuteCommand => $attr{$name}{ampMuteCommand} || 'Mute'
);
$hash->{httpParams} = {
hash => $hash,
url => $hash->{url},
timeout => $hash->{timeout},
noshutdown => 1,
loglevel => $hash->{httpLoglevel},
errorLoglevel => $hash->{httpErrorLoglevel},
method => 'GET',
callback => \&VolumeLink_ReceiveCommand
HTTP_ERROR_COUNT => 0,
fastRetryInterval => 0.1,
hash => $hash,
url => $hash->{url},
timeout => $hash->{timeout},
noshutdown => 1,
loglevel => $hash->{httpLoglevel},
errorLoglevel => $hash->{httpErrorLoglevel},
method => 'GET',
callback => \&VolumeLink_ReceiveCommand
};
readingsSingleUpdate($hash,'state','off',1) if($hash->{STARTED} == 0 && ReadingsVal($name,'state','') ne 'off');
@ -175,17 +177,28 @@ sub VolumeLink_SendCommand($) {
sub VolumeLink_ReceiveCommand($) {
my ($param, $err, $data) = @_;
my $name = $param->{hash}->{NAME};
my $interval = $param->{hash}->{interval};
Log3 $name, 5, "$name: ReceiveCommand - executed";
if($err ne "") {
Log3 $name, $param->{errorLoglevel}, "$name: Error while requesting ".$param->{url}." - $err";
readingsSingleUpdate($param->{hash},'lastHttpError',$err,0);
if($err ne "") {
if($interval > $param->{fastRetryInterval} && $err =~ /timed.out/ && $param->{HTTP_ERROR_COUNT} < 3) {
$interval = $param->{fastRetryInterval};
$param->{HTTP_ERROR_COUNT}++;
readingsSingleUpdate($param->{hash},'lastHttpError',"$err #$param->{HTTP_ERROR_COUNT} of 3, do fast-retry in $interval sec.",0);
Log3 $name, $param->{errorLoglevel}, "$name: Error while requesting ".$param->{url}." - $err - Fast-retry #$param->{HTTP_ERROR_COUNT} of 3 in $interval seconds.";
}
else {
readingsSingleUpdate($param->{hash},'lastHttpError',"$err, retry in $interval sec.",0);
Log3 $name, $param->{errorLoglevel}, "$name: Error while requesting ".$param->{url}." - $err - Retry in $interval seconds.";
}
}
elsif($data ne "") {
Log3 $name, $param->{loglevel}, "$name: url ".$param->{url}." returned: $data";
$param->{HTTP_ERROR_COUNT} = 0;
my($vol,$mute) = $data =~ /$param->{hash}->{volumeRegexPattern}/m;
$vol = int($vol);
@ -230,7 +243,7 @@ sub VolumeLink_ReceiveCommand($) {
}
if($param->{hash}->{STARTED} == 1) {
InternalTimer(time()+$param->{hash}->{interval}, 'VolumeLink_SendCommand', $param->{hash}, 0);
InternalTimer(time()+$interval, 'VolumeLink_SendCommand', $param->{hash}, 0);
}
return undef;
}