mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
70_PylonLowVoltage: contrib V0.1.3
git-svn-id: https://svn.fhem.de/fhem/trunk@27880 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0b8aceba98
commit
b5ea98ef25
@ -116,7 +116,7 @@ BEGIN {
|
||||
|
||||
# Versions History intern (Versions history by Heiko Maaz)
|
||||
my %vNotesIntern = (
|
||||
"0.1.3" => "22.08.2023 permanent socket management, attr gatewayPermLink, improve responseCheck ",
|
||||
"0.1.3" => "22.08.2023 improve responseCheck and others ",
|
||||
"0.1.2" => "20.08.2023 commandref revised, analogValue -> use 'user defined items', refactoring according PBP ",
|
||||
"0.1.1" => "16.08.2023 integrate US3000C, add print request command in HEX to Logfile, attr timeout ".
|
||||
"change validation of received data, change DEF format, extend evaluation of chargeManagmentInfo ".
|
||||
@ -131,7 +131,6 @@ my $invalid = 'unknown'; # default v
|
||||
my $definterval = 30; # default Abrufintervall der Batteriewerte
|
||||
my $defto = 0.5; # default connection Timeout zum RS485 Gateway
|
||||
my @blackl = qw(state nextCycletime); # Ausnahmeliste deleteReadingspec
|
||||
my $gpldef = 0; # Gateway permanent Link = 0 per default
|
||||
|
||||
# Steuerhashes
|
||||
###############
|
||||
@ -285,7 +284,6 @@ sub Initialize {
|
||||
$hash->{AttrFn} = \&Attr;
|
||||
$hash->{ShutdownFn} = \&Shutdown;
|
||||
$hash->{AttrList} = "disable:1,0 ".
|
||||
"gatewayPermLink:1,0 ".
|
||||
"interval ".
|
||||
"timeout ".
|
||||
$readingFnAttributes;
|
||||
@ -434,7 +432,6 @@ sub Update {
|
||||
|
||||
my $interval = AttrVal ($name, 'interval', $definterval); # 0 -> manuell gesteuert
|
||||
my $timeout = AttrVal ($name, 'timeout', $defto);
|
||||
my $gpl = AttrVal ($name, 'gatewayPermLink', $gpldef);
|
||||
my %readings = ();
|
||||
|
||||
my ($socket, $success);
|
||||
@ -457,7 +454,7 @@ sub Update {
|
||||
local $SIG{ALRM} = sub { croak 'gatewaytimeout' };
|
||||
ualarm ($timeout * 1000000); # ualarm in Mikrosekunden
|
||||
|
||||
$socket = _createSocket ($hash, $timeout, \%readings);
|
||||
$socket = _openSocket ($hash, $timeout, \%readings);
|
||||
return if(!$socket);
|
||||
|
||||
if (ReadingsAge ($name, "serialNumber", 601) >= 60) { # relativ statische Werte abrufen
|
||||
@ -495,7 +492,7 @@ sub Update {
|
||||
}
|
||||
|
||||
ualarm(0);
|
||||
_closeSocket ($hash) if(!$gpl);
|
||||
_closeSocket ($hash);
|
||||
|
||||
if ($success) {
|
||||
Log3 ($name, 4, "$name - got data from battery number >$hash->{BATADDRESS}< successfully");
|
||||
@ -512,7 +509,7 @@ return;
|
||||
###############################################################
|
||||
# Socket erstellen
|
||||
###############################################################
|
||||
sub _createSocket {
|
||||
sub _openSocket {
|
||||
my $hash = shift;
|
||||
my $timeout = shift;
|
||||
my $readings = shift; # Referenz auf das Hash der zu erstellenden Readings
|
||||
@ -531,22 +528,20 @@ sub _createSocket {
|
||||
undef $socket;
|
||||
}
|
||||
|
||||
if (!$socket || $socket->connected()) {
|
||||
if (!$socket) {
|
||||
$socket = IO::Socket::INET->new( Proto => 'tcp',
|
||||
PeerAddr => $hash->{HOST},
|
||||
PeerPort => $hash->{PORT},
|
||||
Timeout => $timeout
|
||||
);
|
||||
}
|
||||
|
||||
if (!$socket) {
|
||||
doOnError ({ hash => $hash,
|
||||
readings => $readings,
|
||||
state => 'no socket is established to RS485 gateway',
|
||||
verbose => 3
|
||||
}
|
||||
);
|
||||
return;
|
||||
)
|
||||
or do { doOnError ({ hash => $hash,
|
||||
readings => $readings,
|
||||
state => 'no connection is established to RS485 gateway',
|
||||
verbose => 3
|
||||
}
|
||||
);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
IO::Socket::Timeout->enable_timeouts_on ($socket); # nur notwendig für read or write timeout
|
||||
@ -555,7 +550,7 @@ sub _createSocket {
|
||||
|
||||
$socket->read_timeout ($rwto); # Read/Writetimeout immer kleiner als Sockettimeout
|
||||
$socket->write_timeout ($rwto);
|
||||
$socket->autoflush(1);
|
||||
$socket->autoflush();
|
||||
|
||||
$hash->{SOCKET} = $socket;
|
||||
|
||||
@ -997,9 +992,9 @@ sub Reread {
|
||||
croak 'Timeout reading data from battery';
|
||||
}
|
||||
|
||||
$res = $res . $singlechar if (!(length($res) == 0 && ord($singlechar) == 13)) # ord 13 -> ASCII dezimal für CR (Hex 0d)
|
||||
$res = $res . $singlechar;
|
||||
|
||||
} while (length($res) == 0 || ord($singlechar) != 13);
|
||||
} while (ord($singlechar) != 13);
|
||||
|
||||
return $res;
|
||||
}
|
||||
@ -1257,16 +1252,6 @@ management system via the RS485 interface.
|
||||
</li>
|
||||
<br>
|
||||
|
||||
<a id="PylonLowVoltage-attr-gatewayPermLink"></a>
|
||||
<li><b>gatewayPermLink 0|1</b><br>
|
||||
If set, the connection to the RS485 gateway is not terminated after the data retrieval. Only in case of an error an
|
||||
existing connection is discarded and re-established.
|
||||
If the attribute is not set or 0, a new gateway connection is established before each data fetch which
|
||||
is always terminated again after the data retrieval. <br>
|
||||
(default: 0)
|
||||
</li>
|
||||
<br>
|
||||
|
||||
<a id="PylonLowVoltage-attr-interval"></a>
|
||||
<li><b>interval <seconds></b><br>
|
||||
Interval of the data request from the battery in seconds. If "interval" is explicitly set to the value "0", there is
|
||||
@ -1428,16 +1413,6 @@ Batteriemanagementsystem über die RS485-Schnittstelle zur Verfügung stellt.
|
||||
</li>
|
||||
<br>
|
||||
|
||||
<a id="PylonLowVoltage-attr-gatewayPermLink"></a>
|
||||
<li><b>gatewayPermLink 0|1</b><br>
|
||||
Wenn gesetzt, wird die Verbindung zum RS485 Gateway nach dem Datenabruf nicht abgebaut. Nur im Fehlerfall wird eine
|
||||
bestehende Verbindung verworfen und neu aufgebaut.
|
||||
Ist das Attribut nicht gesetzt bzw. 0, erfolgt vor jedem Datenabruf der Aufbau einer neuen Gatewayverbindung die
|
||||
nach dem Datenabruf grundsätzlich wieder beendet wird. <br>
|
||||
(default: 0)
|
||||
</li>
|
||||
<br>
|
||||
|
||||
<a id="PylonLowVoltage-attr-interval"></a>
|
||||
<li><b>interval <Sekunden></b><br>
|
||||
Intervall der Datenabfrage von der Batterie in Sekunden. Ist "interval" explizit auf den Wert "0" gesetzt, erfolgt
|
||||
|
Loading…
x
Reference in New Issue
Block a user