mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-08 13:24:56 +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:
parent
7c452ff007
commit
ad7bc5a086
@ -449,6 +449,8 @@ sub Start($) {
|
||||
|
||||
sub Stop($) {
|
||||
my $hash = shift;
|
||||
|
||||
$hash->{".reconnectmark"} = 0;
|
||||
|
||||
my $cstate=ReadingsVal($hash->{NAME},"connection","");
|
||||
if($cstate eq "disconnected" || $cstate eq "timed-out") {
|
||||
@ -459,6 +461,7 @@ sub Stop($) {
|
||||
DevIo_CloseDev($hash);
|
||||
RemoveInternalTimer($hash);
|
||||
readingsSingleUpdate($hash,"connection","disconnected",1);
|
||||
readingsSingleUpdate($hash,"state","disconnected",1);
|
||||
}
|
||||
|
||||
sub Ready($) {
|
||||
@ -482,11 +485,13 @@ sub Init($) {
|
||||
readingsSingleUpdate($hash,"connection","connecting",1);
|
||||
$hash->{ping_received}=1;
|
||||
Timer($hash);
|
||||
$hash->{".reconnectmark"} = 1;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub Timer($) {
|
||||
my $hash = shift;
|
||||
#Log3($hash->{NAME},1,">>> timer ");
|
||||
RemoveInternalTimer($hash);
|
||||
unless ($hash->{ping_received}) {
|
||||
onTimeout($hash);
|
||||
@ -494,6 +499,15 @@ sub Timer($) {
|
||||
GP_ForallClients($hash,\¬ify_client_connection_timeout);
|
||||
}
|
||||
$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);
|
||||
send_ping($hash);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user