add fix for 503 Error, make robust

This commit is contained in:
Marko Oldenburg 2020-01-11 14:26:00 +01:00
parent 20d1b39c3c
commit 28e3a80aa9
2 changed files with 35 additions and 17 deletions

View File

@ -210,6 +210,7 @@ sub NUKIBridge_Define($$) {
$hash->{BRIDGEAPI} = $bridgeapi; $hash->{BRIDGEAPI} = $bridgeapi;
$hash->{helper}->{aliveCount} = 0; $hash->{helper}->{aliveCount} = 0;
$hash->{helper}->{actionQueue} = []; $hash->{helper}->{actionQueue} = [];
$hash->{helper}->{iowrite} = 0;
my $infix = 'NUKIBridge'; my $infix = 'NUKIBridge';
Log3( $name, 3, Log3( $name, 3,
@ -505,14 +506,17 @@ sub NUKIBridge_GetCheckBridgeAlive($) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
Log3( $name, 4, "NUKIBridge ($name) - NUKIBridge_GetCheckBridgeAlive" ); Log3( $name, 4, "NUKIBridge ($name) - NUKIBridge_GetCheckBridgeAlive" );
if ( !IsDisabled($name) ) { if ( !IsDisabled($name)
and $hash->{helper}->{iowrite} == 0 ) {
NUKIBridge_Write( $hash, 'info', undef, undef, undef ); NUKIBridge_Write( $hash, 'info', undef, undef, undef );
Log3( $name, 4, "NUKIBridge ($name) - run NUKIBridge_Write" ); Log3( $name, 4, "NUKIBridge ($name) - run NUKIBridge_Write" );
} }
InternalTimer( gettimeofday() + 15 + int( rand(15) ), # InternalTimer( gettimeofday() + 15 + int( rand(15) ),
# 'NUKIBridge_GetCheckBridgeAlive', $hash );
InternalTimer( gettimeofday() + 10,
'NUKIBridge_GetCheckBridgeAlive', $hash ); 'NUKIBridge_GetCheckBridgeAlive', $hash );
Log3( $name, 4, Log3( $name, 4,
@ -597,22 +601,33 @@ sub NUKIBridge_Call($) {
my $endpoint = $obj->{endpoint}; my $endpoint = $obj->{endpoint};
my $nukiId = $obj->{nukiId}; my $nukiId = $obj->{nukiId};
my $uri = NUKIBridge_CreateUri( $hash, $obj ); if ( $hash->{helper}->{iowrite} == 0 ) {
my $uri = NUKIBridge_CreateUri( $hash, $obj );
HttpUtils_NonblockingGet( if ( defined($uri) and $uri ) {
{ $hash->{helper}->{iowrite} = 1;
url => $uri,
timeout => 60, HttpUtils_NonblockingGet(
hash => $hash, {
nukiId => $nukiId, url => $uri,
endpoint => $endpoint, timeout => 30,
header => 'Accept: application/json', hash => $hash,
method => 'GET', nukiId => $nukiId,
callback => \&NUKIBridge_Distribution, endpoint => $endpoint,
header => 'Accept: application/json',
method => 'GET',
callback => \&NUKIBridge_Distribution,
}
);
Log3( $name, 4, "NUKIBridge ($name) - Send HTTP POST with URL $uri" );
} }
); }
else {
Log3( $name, 4, "NUKIBridge ($name) - Send HTTP POST with URL $uri" ); push( @{ $hash->{helper}->{actionQueue} },$obj )
if ( defined($endpoint)
and $endpoint eq 'lockAction' );
}
} }
sub NUKIBridge_Distribution($$$) { sub NUKIBridge_Distribution($$$) {
@ -634,6 +649,9 @@ sub NUKIBridge_Distribution($$$) {
Log3( $name, 5, "NUKIBridge ($name) - Response ERROR: $err" ); Log3( $name, 5, "NUKIBridge ($name) - Response ERROR: $err" );
Log3( $name, 5, "NUKIBridge ($name) - Response CODE: $param->{code}" ) Log3( $name, 5, "NUKIBridge ($name) - Response CODE: $param->{code}" )
if ( defined( $param->{code} ) and ( $param->{code} ) ); if ( defined( $param->{code} ) and ( $param->{code} ) );
$hash->{helper}->{iowrite} = 0
if ( $hash->{helper}->{iowrite} == 1 );
readingsBeginUpdate($hash); readingsBeginUpdate($hash);

View File

@ -361,7 +361,7 @@ sub NUKIDevice_Set($$@) {
$hash->{helper}{lockAction} = $lockAction; $hash->{helper}{lockAction} = $lockAction;
IOWrite( $hash, "lockAction", $lockAction, $hash->{NUKIID}, IOWrite( $hash, 'lockAction', $lockAction, $hash->{NUKIID},
$hash->{DEVICETYPE} ); $hash->{DEVICETYPE} );
return undef; return undef;