mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
93_FHEM2FHEM.pm: add "set cmd" and "attr keepaliveInterval" (Forum #122805)
git-svn-id: https://svn.fhem.de/fhem/trunk@24939 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
45fc89db3e
commit
c44ec53ad7
@ -35,14 +35,15 @@ FHEM2FHEM_Initialize($)
|
|||||||
no warnings 'qw';
|
no warnings 'qw';
|
||||||
my @attrList = qw(
|
my @attrList = qw(
|
||||||
addStateEvent:1,0
|
addStateEvent:1,0
|
||||||
dummy:1,0
|
|
||||||
disable:0,1
|
disable:0,1
|
||||||
disabledForIntervals
|
disabledForIntervals
|
||||||
|
dummy:1,0
|
||||||
eventOnly:1,0
|
eventOnly:1,0
|
||||||
excludeEvents
|
excludeEvents
|
||||||
loopThreshold
|
loopThreshold
|
||||||
setState
|
keepaliveInterval
|
||||||
reportConnected:1,0
|
reportConnected:1,0
|
||||||
|
setState
|
||||||
);
|
);
|
||||||
use warnings 'qw';
|
use warnings 'qw';
|
||||||
$hash->{AttrList} = join(" ", @attrList);
|
$hash->{AttrList} = join(" ", @attrList);
|
||||||
@ -160,6 +161,24 @@ FHEM2FHEM_Read($)
|
|||||||
#Log3 $hash, 5, "FHEM2FHEM/RAW: $data/$buf";
|
#Log3 $hash, 5, "FHEM2FHEM/RAW: $data/$buf";
|
||||||
$data .= $buf;
|
$data .= $buf;
|
||||||
|
|
||||||
|
if($data =~ m/\0/) {
|
||||||
|
if($data !~ m/^(.*)\0(.*)\0(.*)$/s) {
|
||||||
|
$hash->{PARTIAL} = $data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $resp = $2;
|
||||||
|
if($hash->{".lcmd"}) {
|
||||||
|
Log3 $name, 4, "Remote command response:$resp";
|
||||||
|
asyncOutput($hash->{".lcmd"}, $resp);
|
||||||
|
delete($hash->{".lcmd"});
|
||||||
|
} else {
|
||||||
|
Log3 $name, 3, "Remote command response:$resp";
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $1.$3; # Continue with the rest
|
||||||
|
}
|
||||||
|
|
||||||
while($data =~ m/\n/) {
|
while($data =~ m/\n/) {
|
||||||
my $rmsg;
|
my $rmsg;
|
||||||
($rmsg,$data) = split("\n", $data, 2);
|
($rmsg,$data) = split("\n", $data, 2);
|
||||||
@ -297,6 +316,9 @@ FHEM2FHEM_OpenDev($$)
|
|||||||
syswrite($hash->{TCPDev}, $msg . "\n");
|
syswrite($hash->{TCPDev}, $msg . "\n");
|
||||||
syswrite($hash->{TCPDev}, "trigger global CONNECTED $name\n")
|
syswrite($hash->{TCPDev}, "trigger global CONNECTED $name\n")
|
||||||
if(AttrVal($name, "reportConnected", 0));
|
if(AttrVal($name, "reportConnected", 0));
|
||||||
|
|
||||||
|
my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0);
|
||||||
|
InternalTimer(gettimeofday()+$ki, "FHEM2FHEM_keepalive", $hash) if($ki);
|
||||||
};
|
};
|
||||||
|
|
||||||
return HttpUtils_Connect({ # Nonblocking
|
return HttpUtils_Connect({ # Nonblocking
|
||||||
@ -346,14 +368,25 @@ sub
|
|||||||
FHEM2FHEM_Set($@)
|
FHEM2FHEM_Set($@)
|
||||||
{
|
{
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
|
my %sets = ( reopen=>"noArg", cmd=>"textField" );
|
||||||
|
|
||||||
return "set needs at least one parameter" if(@a < 2);
|
return "set needs at least one parameter" if(@a < 2);
|
||||||
return "Unknown argument $a[1], choose one of reopen:noArg"
|
return "Unknown argument $a[1], choose one of ".
|
||||||
if($a[1] ne "reopen");
|
join(" ", map {"$_:$sets{$_}"} sort keys %sets) if(!$sets{$a[1]});
|
||||||
|
return "$a[1] needs at least one parameter"
|
||||||
|
if(@a < 3 && $sets{$a[1]} ne "noArg");
|
||||||
|
|
||||||
|
if($a[1] eq "reopen") {
|
||||||
FHEM2FHEM_CloseDev($hash);
|
FHEM2FHEM_CloseDev($hash);
|
||||||
FHEM2FHEM_OpenDev($hash, 0);
|
FHEM2FHEM_OpenDev($hash, 0);
|
||||||
|
}
|
||||||
|
if($a[1] eq "cmd") {
|
||||||
|
return "Not connected" if($hash->{STATE} ne "connected");
|
||||||
|
my $cmd = join(" ",@a[2..$#a]);
|
||||||
|
$cmd = '{my $r=fhem("'.$cmd.'");; defined($r) ? "\\0$r\\0" : $r}'."\n";
|
||||||
|
syswrite($hash->{TCPDev}, $cmd);
|
||||||
|
$hash->{".lcmd"} = $hash->{CL};
|
||||||
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,13 +396,31 @@ FHEM2FHEM_Attr(@)
|
|||||||
my ($type, $devName, $attrName, @param) = @_;
|
my ($type, $devName, $attrName, @param) = @_;
|
||||||
my $hash = $defs{$devName};
|
my $hash = $defs{$devName};
|
||||||
|
|
||||||
return undef if($attrName && $attrName ne "addStateEvent");
|
if($attrName eq "addStateEvent") {
|
||||||
$attr{$devName}{$attrName} = 1;
|
$attr{$devName}{$attrName} = 1;
|
||||||
FHEM2FHEM_CloseDev($hash);
|
FHEM2FHEM_CloseDev($hash);
|
||||||
FHEM2FHEM_OpenDev($hash, 1);
|
FHEM2FHEM_OpenDev($hash, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($attrName eq "keepaliveInterval") {
|
||||||
|
return "Numeric argument expected" if($param[0] !~ m/^\d+$/);
|
||||||
|
InternalTimer(gettimeofday()+$param[0], "FHEM2FHEM_keepalive", $hash)
|
||||||
|
if($param[0] && $hash->{TCPDev});
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
FHEM2FHEM_keepalive($)
|
||||||
|
{
|
||||||
|
my ($hash) = @_;
|
||||||
|
my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0);
|
||||||
|
return if(!$ki || !$hash->{TCPDev});
|
||||||
|
syswrite($hash->{TCPDev}, "{undef}\n");
|
||||||
|
InternalTimer(gettimeofday()+$ki, "FHEM2FHEM_keepalive", $hash);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -464,6 +515,12 @@ FHEM2FHEM_Attr(@)
|
|||||||
<ul>
|
<ul>
|
||||||
<li>reopen<br>
|
<li>reopen<br>
|
||||||
Reopens the connection to the device and reinitializes it.</li><br>
|
Reopens the connection to the device and reinitializes it.</li><br>
|
||||||
|
<li>cmd <FHEM-command><br>
|
||||||
|
issues the FHEM-command on the remote machine. Note: a possible answer
|
||||||
|
can be seen if it is issued in a telnet session or in the FHEMWEB
|
||||||
|
"command execution window", but not when issued in the other FHEMWEB
|
||||||
|
input lines. </li><br>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<a id="FHEM2FHEM-get"></a>
|
<a id="FHEM2FHEM-get"></a>
|
||||||
@ -489,6 +546,10 @@ FHEM2FHEM_Attr(@)
|
|||||||
do not publish events matching <regexp>. Note: ^ and $ are
|
do not publish events matching <regexp>. Note: ^ and $ are
|
||||||
automatically added to the regexp, like in notify, FileLog, etc.
|
automatically added to the regexp, like in notify, FileLog, etc.
|
||||||
</li>
|
</li>
|
||||||
|
<li><a id="FHEM2FHEM-attr-keepaliveInterval">keepaliveInterval <sec>
|
||||||
|
</a><br>
|
||||||
|
issues an empty command regularly in order to detect a stale TCP
|
||||||
|
connection faster than the OS.</li>
|
||||||
<li><a id="FHEM2FHEM-attr-loopThreshold">loopThreshold</a><br>
|
<li><a id="FHEM2FHEM-attr-loopThreshold">loopThreshold</a><br>
|
||||||
helps avoiding endless loops. If set, the last update of a given
|
helps avoiding endless loops. If set, the last update of a given
|
||||||
reading must be older than the current value in seconds. Take care if
|
reading must be older than the current value in seconds. Take care if
|
||||||
@ -608,6 +669,11 @@ FHEM2FHEM_Attr(@)
|
|||||||
<ul>
|
<ul>
|
||||||
<li>reopen<br>
|
<li>reopen<br>
|
||||||
Öffnet die Verbindung erneut.</li>
|
Öffnet die Verbindung erneut.</li>
|
||||||
|
<li>cmd <FHEM-command><br>
|
||||||
|
fürt FHEM-command auf dem entfernten Rechner aus. Achtung: eine
|
||||||
|
Fehlermeldung ist nur dann sichtbar, falls der Befehl in einer
|
||||||
|
Telnet-Sitzung oder in der mehrzeiligen FHEMWEB Befehlsdialog
|
||||||
|
eingegeben wurde.</li><br>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<a id="FHEM2FHEM-get"></a>
|
<a id="FHEM2FHEM-get"></a>
|
||||||
@ -634,6 +700,10 @@ FHEM2FHEM_Attr(@)
|
|||||||
bereitgestellt. Achtung: ^ und $ werden automatisch hinzugefuuml;gt, wie
|
bereitgestellt. Achtung: ^ und $ werden automatisch hinzugefuuml;gt, wie
|
||||||
bei notify, FileLog, usw.
|
bei notify, FileLog, usw.
|
||||||
</li>
|
</li>
|
||||||
|
<li><a id="FHEM2FHEM-attr-keepaliveInterval">keepaliveInterval <sec>
|
||||||
|
</a><br>
|
||||||
|
setzt regelmaessig einen leeren Befehl ab, um einen Verbindungsabbruch
|
||||||
|
frueher als das OS feststellen zu koennen.</li>
|
||||||
<li><a id="FHEM2FHEM-attr-loopThreshold">loopThreshold</a><br>
|
<li><a id="FHEM2FHEM-attr-loopThreshold">loopThreshold</a><br>
|
||||||
hilft Endlosschleifen zu vermeiden. Falls gesetzt, muss die letzte
|
hilft Endlosschleifen zu vermeiden. Falls gesetzt, muss die letzte
|
||||||
Änderung des gleichen Readings mehr als der Wert in Sekunden alt
|
Änderung des gleichen Readings mehr als der Wert in Sekunden alt
|
||||||
|
@ -980,6 +980,8 @@ FW_execRawDef(data)
|
|||||||
doNext()
|
doNext()
|
||||||
{
|
{
|
||||||
if(++i1 >= arr.length) {
|
if(++i1 >= arr.length) {
|
||||||
|
if($("#FW_okDialog").length) // F2F remote cmd execution
|
||||||
|
return;
|
||||||
return FW_okDialog("Executed everything, no errors found.");
|
return FW_okDialog("Executed everything, no errors found.");
|
||||||
}
|
}
|
||||||
str += arr[i1];
|
str += arr[i1];
|
||||||
|
Loading…
Reference in New Issue
Block a user