2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 07:16:03 +00:00

added: auto reconnect

git-svn-id: https://svn.fhem.de/fhem/trunk@21587 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
hexenmeister 2020-04-03 21:49:47 +00:00
parent 7c452ff007
commit ad7bc5a086

View File

@ -450,6 +450,8 @@ sub Start($) {
sub Stop($) { sub Stop($) {
my $hash = shift; my $hash = shift;
$hash->{".reconnectmark"} = 0;
my $cstate=ReadingsVal($hash->{NAME},"connection",""); my $cstate=ReadingsVal($hash->{NAME},"connection","");
if($cstate eq "disconnected" || $cstate eq "timed-out") { if($cstate eq "disconnected" || $cstate eq "timed-out") {
return undef; return undef;
@ -459,6 +461,7 @@ sub Stop($) {
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
readingsSingleUpdate($hash,"connection","disconnected",1); readingsSingleUpdate($hash,"connection","disconnected",1);
readingsSingleUpdate($hash,"state","disconnected",1);
} }
sub Ready($) { sub Ready($) {
@ -482,11 +485,13 @@ sub Init($) {
readingsSingleUpdate($hash,"connection","connecting",1); readingsSingleUpdate($hash,"connection","connecting",1);
$hash->{ping_received}=1; $hash->{ping_received}=1;
Timer($hash); Timer($hash);
$hash->{".reconnectmark"} = 1;
return undef; return undef;
} }
sub Timer($) { sub Timer($) {
my $hash = shift; my $hash = shift;
#Log3($hash->{NAME},1,">>> timer ");
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
unless ($hash->{ping_received}) { unless ($hash->{ping_received}) {
onTimeout($hash); onTimeout($hash);
@ -494,6 +499,15 @@ sub Timer($) {
GP_ForallClients($hash,\&notify_client_connection_timeout); GP_ForallClients($hash,\&notify_client_connection_timeout);
} }
$hash->{ping_received} = 0; $hash->{ping_received} = 0;
#Log3($hash->{NAME},1,">>> reconnect mark: ".$hash->{".reconnectmark"});
#Log3($hash->{NAME},1,">>> state: ".ReadingsVal($hash->{NAME}, "state", ""));
if($hash->{".reconnectmark"} eq 1) {
if(ReadingsVal($hash->{NAME}, "state", "") eq "disconnected") {
#Log3($hash->{NAME},1,">>> reconnect ");
Start($hash);
}
}
InternalTimer(gettimeofday()+$hash->{timeout}, "MQTT::Timer", $hash, 0); InternalTimer(gettimeofday()+$hash->{timeout}, "MQTT::Timer", $hash, 0);
send_ping($hash); send_ping($hash);
} }