47_OBIS: Fix for broken Datasets of type 255.255.255.255

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12976 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Icinger 2017-01-06 11:56:02 +00:00
parent 48409374cb
commit 22cb670e36

View File

@ -76,7 +76,7 @@ sub OBIS_Initialize($)
$hash->{ReadyFn} = "OBIS_Ready"; $hash->{ReadyFn} = "OBIS_Ready";
$hash->{DefFn} = "OBIS_Define"; $hash->{DefFn} = "OBIS_Define";
$hash->{ParseFn} = "OBIS_Parse"; $hash->{ParseFn} = "OBIS_Parse";
$hash->{SetFn} = "OBIS_Set"; # $hash->{SetFn} = "OBIS_Set";
$hash->{UndefFn} = "OBIS_Undef"; $hash->{UndefFn} = "OBIS_Undef";
$hash->{AttrFn} = "OBIS_Attr"; $hash->{AttrFn} = "OBIS_Attr";
@ -130,6 +130,7 @@ sub OBIS_Define($$)
} }
my %bd=("300"=>"0","600"=>"1","1200"=>"2","2400"=>"3","4800"=>"4","9600"=>"5","18200"=>"6","36400"=>"7","57600"=>"8","115200"=>"9"); my %bd=("300"=>"0","600"=>"1","1200"=>"2","2400"=>"3","4800"=>"4","9600"=>"5","18200"=>"6","36400"=>"7","57600"=>"8","115200"=>"9");
$hash->{helper}{SPEED}=$bd{$baudrate}; $hash->{helper}{SPEED}=$bd{$baudrate};
$hash->{helper}{SPEED2}=$bd{$a[4]//$baudrate};
} }
else {$baudrate=9600; $hash->{helper}{SPEED}="5";} else {$baudrate=9600; $hash->{helper}{SPEED}="5";}
@ -233,7 +234,6 @@ sub OBIS_Read($)
if ( !defined($hash->{helper}{SpeedChange}) || ($hash->{helper}{SpeedChange} eq "")) if ( !defined($hash->{helper}{SpeedChange}) || ($hash->{helper}{SpeedChange} eq ""))
{ {
OBIS_Parse($hash,$buf) if ($hash->{helper}{EoM}!=1); OBIS_Parse($hash,$buf) if ($hash->{helper}{EoM}!=1);
Log3 $hash,4, "parsing....\r\n";
} else } else
{ {
# if ($hash->{helper}{SpeedChange2} eq "") # if ($hash->{helper}{SpeedChange2} eq "")
@ -283,6 +283,8 @@ sub OBIS_Read($)
sub OBIS_trySMLdecode($$) sub OBIS_trySMLdecode($$)
{ {
my ( $hash, $remainingSML ) = @_; my ( $hash, $remainingSML ) = @_;
my $t=$remainingSML;
if ($remainingSML=~m/SML\((.*)\)/g) {$remainingSML=$1};
if($remainingSML!~/[\x00-\x09|\x10-\x1F]/g) {return $remainingSML} else {$hash->{MeterType}="SML"}; if($remainingSML!~/[\x00-\x09|\x10-\x1F]/g) {return $remainingSML} else {$hash->{MeterType}="SML"};
$remainingSML=uc(unpack('H*',$remainingSML)); $remainingSML=uc(unpack('H*',$remainingSML));
$hash->{MeterType}="SML"; $hash->{MeterType}="SML";
@ -290,6 +292,8 @@ sub OBIS_trySMLdecode($$)
while ($remainingSML=~/(1B1B1B1B010101.*?1B1B1B1B1A[0-9A-F]{6})/mip) { while ($remainingSML=~/(1B1B1B1B010101.*?1B1B1B1B1A[0-9A-F]{6})/mip) {
my $msg=$1; my $msg=$1;
Log3 $hash,5,"SML-Parse $1";
$remainingSML=${^POSTMATCH}; $remainingSML=${^POSTMATCH};
if (OBIS_CRC16($hash,pack('H*',$msg)) == 1) { if (OBIS_CRC16($hash,pack('H*',$msg)) == 1) {
$remainingSML=""; #reset possible further messages if actual CRC ok; if someone misses some messages, we remove it. $remainingSML=""; #reset possible further messages if actual CRC ok; if someone misses some messages, we remove it.
@ -298,20 +302,33 @@ sub OBIS_trySMLdecode($$)
my $OBISid=$msg=~m/7701([0-9A-F]*?)01/g; my $OBISid=$msg=~m/7701([0-9A-F]*?)01/g;
Log3 $hash,5,"OBIS: Full message-> $msg"; Log3 $hash,5,"OBIS: Full message-> $msg";
(undef,undef,$OBISid,undef)=OBIS_decodeTL($1); (undef,undef,$OBISid,undef)=OBIS_decodeTL($1);
# Log3 $hash,5,"OBIS: ObisID-> $1";
while ($msg =~ m/(7707)([0-9A-F]*)/g) { while ($msg =~ m/(7707)([0-9A-F]*)/g) {
# my $telegramm = $&; # my $telegramm = $&;
my @list=$&=~/(7707)([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]*)/g; my @list=$&=~/(7707)([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]*)/g;
Log3 $hash, 5,"OBIS: Telegram=$msg"; Log3 $hash, 5,"OBIS: Telegram=$msg";
# Log 3,@list; Log 3,Dumper(@list);
if (!@list) {Log3 $hash,3,"OBIS - Empty datagram: .$msg"}; if (!@list) {Log3 $hash,3,"OBIS - Empty datagram: .$msg"};
my $line=hex($list[1])."-".hex($list[2]).":".hex($list[3]).".".hex($list[4]).".".hex($list[5])."*255("; my $line=hex($list[1])."-".hex($list[2]).":".hex($list[3]).".".hex($list[4]).".".hex($list[5])."*255(";
if ($line eq '255-255:255.255.255*255(') {
$list[7]=~/(7707.*)/;
$msg=$1;
} else
{
# Log3 $hash,5,"Line: $line";
# Log3 $hash,5,"Before decoding: $list[7]";
my ($status,$statusL,$statusT,$valTime,$valTimeL,$valTimeT,$unit,$unitL,$unitT,$scaler,$scalerL,$scalerT,$data,$dataL,$dataT,$other); my ($status,$statusL,$statusT,$valTime,$valTimeL,$valTimeT,$unit,$unitL,$unitT,$scaler,$scalerL,$scalerT,$data,$dataL,$dataT,$other);
($statusL,$statusT,$status,$other)=OBIS_decodeTL($list[7]); ($statusL,$statusT,$status,$other)=OBIS_decodeTL($list[7]);
# Log3 $hash,5,"After status: $other";
($valTimeL,$valTimeT,$valTime,$other)=OBIS_decodeTL($other); ($valTimeL,$valTimeT,$valTime,$other)=OBIS_decodeTL($other);
# Log3 $hash,5,"After Time: $other";
($unitL,$unitT,$unit,$other)=OBIS_decodeTL($other); ($unitL,$unitT,$unit,$other)=OBIS_decodeTL($other);
# Log3 $hash,5,"After Unit: $other";
($scalerL,$scalerT,$scaler,$other)=OBIS_decodeTL($other); ($scalerL,$scalerT,$scaler,$other)=OBIS_decodeTL($other);
# Log3 $hash,5,"After Scaler: $other";
($dataL,$dataT,$data,$msg)=OBIS_decodeTL($other); ($dataL,$dataT,$data,$msg)=OBIS_decodeTL($other);
# Log3 $hash,5,"After Data: $msg";
# Type String # Type String
my $line2=""; my $line2="";
if ($dataT ==0 ) { if ($dataT ==0 ) {
@ -367,11 +384,12 @@ $line2=$data;
$newMsg.=$line.$line2.")\r\n"; $newMsg.=$line.$line2.")\r\n";
# Log 3,"$line$line2)"; # Log 3,"$line$line2)";
###### TypeLength-Test ends here ###### TypeLength-Test ends here
}
} }
$initstr=~s/\\$//; $initstr=~s/\\$//;
$newMsg=$initstr.chr(13).chr(10).$newMsg; $newMsg=$initstr.chr(13).chr(10).$newMsg;
$newMsg.="!".chr(13).chr(10); $newMsg.="!".chr(13).chr(10);
Log3 $hash,4,"MSG IS: \r\n$newMsg";
} else { } else {
# Log 3,"Illegal CRC"; # Log 3,"Illegal CRC";
$hash->{CRC_Errors}+=1; $hash->{CRC_Errors}+=1;
@ -385,7 +403,6 @@ sub OBIS_Parse($$)
{ {
my ($hash, $buf) = @_; my ($hash, $buf) = @_;
my $buf2=uc(unpack('H*',$buf)); my $buf2=uc(unpack('H*',$buf));
Log 5,"uedduhskhdkjhsdkjh";
if($hash->{MeterType}!~/SML|Unknown/ && $buf2=~m/7701([0-9A-F]*?)01/g) { if($hash->{MeterType}!~/SML|Unknown/ && $buf2=~m/7701([0-9A-F]*?)01/g) {
Log 3,"OBIS_Ext called"; Log 3,"OBIS_Ext called";
my (undef,undef,$OBISid,undef)=OBIS_decodeTL($1); my (undef,undef,$OBISid,undef)=OBIS_decodeTL($1);
@ -743,6 +760,7 @@ sub OBIS_decodeTL($){
$msg=substr($msg,2); $msg=substr($msg,2);
$msgLength=($msgLength*16) + ($lt & 0b00001111); $msgLength=($msgLength*16) + ($lt & 0b00001111);
} while ($lt & 0b10000000); } while ($lt & 0b10000000);
# Log 3,"Calculated length: $msgLength";
if ($msgType == 0b01110000) { if ($msgType == 0b01110000) {
for (my $i=0;$i<$msgLength;$i++) { for (my $i=0;$i<$msgLength;$i++) {
my $tmp2=""; my $tmp2="";
@ -802,15 +820,8 @@ sub OBIS_decodeTL($){
</li> </li>
<li> <li>
<code>channels</code><br> <code>channels</code><br>
With this, you can adjust the reported channels. With this, you can rename the reported channels.
OBIS-Standard is <code>attr myOBIS channels {"1.0.96.5.5.255"=>"Status","1.0.0.0.0.255"=>"Info","16.7"=>"Verbrauch"}></code>
<ul>
<li>1-->Sum of all phases</li>
<li>21-->Phase 1</li>
<li>41-->Phase 2</li>
<li>61-->Phase 3</li></ul>
You can change that for example to:
<code>attr myOBIS channels {"2"=>"L1", "4"=>"L2", "6"=>"L3"}</code>
<br><br></li> <br><br></li>
<li><code>directions</code><br> <li><code>directions</code><br>
Some Meters report feeding/comnsuming of power in a statusword. Some Meters report feeding/comnsuming of power in a statusword.
@ -820,7 +831,7 @@ sub OBIS_decodeTL($){
</li> </li>
<li> <li>
<code>interval</code><br> <code>interval</code><br>
The polling-interval in seconds The polling-interval in seconds. (Only useful in Polling-Mode)
</li> </li>
<li> <li>
<code>alignTime</code><br> <code>alignTime</code><br>
@ -874,15 +885,9 @@ sub OBIS_decodeTL($){
</li> </li>
<li> <li>
<code>channels</code><br> <code>channels</code><br>
Hiermit können die einzelnen Kanal-Readings angepasst werden. Hiermit können die einzelnen Kanal-Readings mittels RegExes umbenannt werden.
OBIS-Standard ist
<ul>
<li>1-->Summe aller Phasen</li>
<li>21-->Phase 1</li>
<li>41-->Phase 2</li>
<li>61-->Phase 3</li></ul>
Beispiel: Beispiel:
<code>attr myOBIS channels {"2"=>"L1", "4"=>"L2", "6"=>"L3"}></code> <code>attr myOBIS channels {"1.0.96.5.5.255"=>"Status","1.0.0.0.0.255"=>"Info","16.7"=>"Verbrauch"}></code>
<br><br> <br><br>
</li> </li>
<li><code>directions</code><br> <li><code>directions</code><br>
@ -892,7 +897,7 @@ sub OBIS_decodeTL($){
<code>attr myOBIS directions {">" => "pwr consuming", "<"=>"pwr feeding"}</code> <code>attr myOBIS directions {">" => "pwr consuming", "<"=>"pwr feeding"}</code>
</li><li> </li><li>
<code>interval</code><br> <code>interval</code><br>
Abrufinterval der Daten. Abrufinterval der Daten. (Bringt nur im Polling-Mode was)
</li><li> </li><li>
<code>algignTime</code><br> <code>algignTime</code><br>
Richtet den Zeitpunkt von <interval> nach einer bestimmten Uhrzeit aus. Richtet den Zeitpunkt von <interval> nach einer bestimmten Uhrzeit aus.