2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 19:36: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,6 +56,8 @@ sub VolumeLink_Define($$) {
ampMuteCommand => $attr{$name}{ampMuteCommand} || 'Mute' ampMuteCommand => $attr{$name}{ampMuteCommand} || 'Mute'
); );
$hash->{httpParams} = { $hash->{httpParams} = {
HTTP_ERROR_COUNT => 0,
fastRetryInterval => 0.1,
hash => $hash, hash => $hash,
url => $hash->{url}, url => $hash->{url},
timeout => $hash->{timeout}, timeout => $hash->{timeout},
@ -175,17 +177,28 @@ sub VolumeLink_SendCommand($) {
sub VolumeLink_ReceiveCommand($) { sub VolumeLink_ReceiveCommand($) {
my ($param, $err, $data) = @_; my ($param, $err, $data) = @_;
my $name = $param->{hash}->{NAME}; my $name = $param->{hash}->{NAME};
my $interval = $param->{hash}->{interval};
Log3 $name, 5, "$name: ReceiveCommand - executed"; Log3 $name, 5, "$name: ReceiveCommand - executed";
if($err ne "") { if($err ne "") {
Log3 $name, $param->{errorLoglevel}, "$name: Error while requesting ".$param->{url}." - $err"; if($interval > $param->{fastRetryInterval} && $err =~ /timed.out/ && $param->{HTTP_ERROR_COUNT} < 3) {
$interval = $param->{fastRetryInterval};
$param->{HTTP_ERROR_COUNT}++;
readingsSingleUpdate($param->{hash},'lastHttpError',$err,0); 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 "") { elsif($data ne "") {
Log3 $name, $param->{loglevel}, "$name: url ".$param->{url}." returned: $data"; Log3 $name, $param->{loglevel}, "$name: url ".$param->{url}." returned: $data";
$param->{HTTP_ERROR_COUNT} = 0;
my($vol,$mute) = $data =~ /$param->{hash}->{volumeRegexPattern}/m; my($vol,$mute) = $data =~ /$param->{hash}->{volumeRegexPattern}/m;
$vol = int($vol); $vol = int($vol);
@ -230,7 +243,7 @@ sub VolumeLink_ReceiveCommand($) {
} }
if($param->{hash}->{STARTED} == 1) { 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; return undef;
} }