From 319ac2fac38defd1431187b959593b9d8ce266be Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Wed, 7 Oct 2020 14:54:17 +0000 Subject: [PATCH] 00_MQTT2_CLIENT.pm: implement CONNACK timeout (Forum #114166) git-svn-id: https://svn.fhem.de/fhem/trunk@22936 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_MQTT2_CLIENT.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fhem/FHEM/00_MQTT2_CLIENT.pm b/fhem/FHEM/00_MQTT2_CLIENT.pm index 83159ece9..23919b259 100644 --- a/fhem/FHEM/00_MQTT2_CLIENT.pm +++ b/fhem/FHEM/00_MQTT2_CLIENT.pm @@ -131,6 +131,7 @@ MQTT2_CLIENT_doinit($) pack("C",0x10). MQTT2_CLIENT_calcRemainingLength(length($msg)).$msg, 1, 1); # Forum #92946 RemoveInternalTimer($hash); + $hash->{waitingForConnack} = 1; if($keepalive) { InternalTimer(gettimeofday()+$keepalive,"MQTT2_CLIENT_keepalive",$hash,0); } @@ -182,10 +183,13 @@ MQTT2_CLIENT_keepalive($) { my ($hash) = @_; my $name = $hash->{NAME}; + if($hash->{waitingForConnack}) { + Log3 $name, 2, "$hash->{NAME}: No CONNACK, disconnecting"; + return MQTT2_CLIENT_Disco($hash); + } if($hash->{waitingForPingRespSince}) { Log3 $name, 2, "$hash->{NAME}: No PINGRESP for last PINGREQ (". "at $hash->{waitingForPingRespSince}), disconnecting"; - delete $hash->{waitingForPingRespSince}; return MQTT2_CLIENT_Disco($hash); } my $keepalive = AttrVal($name, "keepaliveTimeout", 30); @@ -224,6 +228,9 @@ MQTT2_CLIENT_Disco($;$$) delete($hash->{disconnectTimerHash}); } + delete $hash->{waitingForConnack}; + delete $hash->{waitingForPingRespSince}; + readingsSingleUpdate($hash, "state", "disconnected", 1); } @@ -418,6 +425,7 @@ MQTT2_CLIENT_Read($@) #################################### if($cpt eq "CONNACK") { + delete($hash->{waitingForConnack}); my $rc = ord(substr($pl,1,1)); if($rc == 0) { MQTT2_CLIENT_doinit($hash);