mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +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';
|
||||
my @attrList = qw(
|
||||
addStateEvent:1,0
|
||||
dummy:1,0
|
||||
disable:0,1
|
||||
disabledForIntervals
|
||||
dummy:1,0
|
||||
eventOnly:1,0
|
||||
excludeEvents
|
||||
loopThreshold
|
||||
setState
|
||||
keepaliveInterval
|
||||
reportConnected:1,0
|
||||
setState
|
||||
);
|
||||
use warnings 'qw';
|
||||
$hash->{AttrList} = join(" ", @attrList);
|
||||
@ -160,6 +161,24 @@ FHEM2FHEM_Read($)
|
||||
#Log3 $hash, 5, "FHEM2FHEM/RAW: $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/) {
|
||||
my $rmsg;
|
||||
($rmsg,$data) = split("\n", $data, 2);
|
||||
@ -297,6 +316,9 @@ FHEM2FHEM_OpenDev($$)
|
||||
syswrite($hash->{TCPDev}, $msg . "\n");
|
||||
syswrite($hash->{TCPDev}, "trigger global CONNECTED $name\n")
|
||||
if(AttrVal($name, "reportConnected", 0));
|
||||
|
||||
my $ki = AttrVal($hash->{NAME}, "keepaliveInterval", 0);
|
||||
InternalTimer(gettimeofday()+$ki, "FHEM2FHEM_keepalive", $hash) if($ki);
|
||||
};
|
||||
|
||||
return HttpUtils_Connect({ # Nonblocking
|
||||
@ -346,14 +368,25 @@ sub
|
||||
FHEM2FHEM_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my %sets = ( reopen=>"noArg", cmd=>"textField" );
|
||||
|
||||
return "set needs at least one parameter" if(@a < 2);
|
||||
return "Unknown argument $a[1], choose one of reopen:noArg"
|
||||
if($a[1] ne "reopen");
|
||||
|
||||
return "Unknown argument $a[1], choose one of ".
|
||||
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");
|
||||
|
||||
FHEM2FHEM_CloseDev($hash);
|
||||
FHEM2FHEM_OpenDev($hash, 0);
|
||||
if($a[1] eq "reopen") {
|
||||
FHEM2FHEM_CloseDev($hash);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -363,13 +396,31 @@ FHEM2FHEM_Attr(@)
|
||||
my ($type, $devName, $attrName, @param) = @_;
|
||||
my $hash = $defs{$devName};
|
||||
|
||||
return undef if($attrName && $attrName ne "addStateEvent");
|
||||
$attr{$devName}{$attrName} = 1;
|
||||
FHEM2FHEM_CloseDev($hash);
|
||||
FHEM2FHEM_OpenDev($hash, 1);
|
||||
if($attrName eq "addStateEvent") {
|
||||
$attr{$devName}{$attrName} = 1;
|
||||
FHEM2FHEM_CloseDev($hash);
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
=pod
|
||||
@ -464,6 +515,12 @@ FHEM2FHEM_Attr(@)
|
||||
<ul>
|
||||
<li>reopen<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>
|
||||
|
||||
<a id="FHEM2FHEM-get"></a>
|
||||
@ -489,6 +546,10 @@ FHEM2FHEM_Attr(@)
|
||||
do not publish events matching <regexp>. Note: ^ and $ are
|
||||
automatically added to the regexp, like in notify, FileLog, etc.
|
||||
</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>
|
||||
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
|
||||
@ -608,6 +669,11 @@ FHEM2FHEM_Attr(@)
|
||||
<ul>
|
||||
<li>reopen<br>
|
||||
Ö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>
|
||||
|
||||
<a id="FHEM2FHEM-get"></a>
|
||||
@ -634,6 +700,10 @@ FHEM2FHEM_Attr(@)
|
||||
bereitgestellt. Achtung: ^ und $ werden automatisch hinzugefuuml;gt, wie
|
||||
bei notify, FileLog, usw.
|
||||
</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>
|
||||
hilft Endlosschleifen zu vermeiden. Falls gesetzt, muss die letzte
|
||||
Änderung des gleichen Readings mehr als der Wert in Sekunden alt
|
||||
|
@ -980,6 +980,8 @@ FW_execRawDef(data)
|
||||
doNext()
|
||||
{
|
||||
if(++i1 >= arr.length) {
|
||||
if($("#FW_okDialog").length) // F2F remote cmd execution
|
||||
return;
|
||||
return FW_okDialog("Executed everything, no errors found.");
|
||||
}
|
||||
str += arr[i1];
|
||||
|
Loading…
Reference in New Issue
Block a user