diff --git a/contrib/1-Wire/00_OWX.pm b/contrib/1-Wire/00_OWX.pm index c9aba2842..501707374 100644 --- a/contrib/1-Wire/00_OWX.pm +++ b/contrib/1-Wire/00_OWX.pm @@ -6,7 +6,7 @@ # via an active DS2480/DS2490/DS9097U bus master interface or # via a passive DS9097 interface # -# Version 1.0 - February 21, 2012 +# Version 1.01 - February 23, 2012 # # Prof. Dr. Peter A. Henning, 2011 # @@ -366,53 +366,62 @@ sub OWX_Discover ($) { while( $owx_LastDeviceFlag==0 && $res!=0 ){ $res = $res & OWX_Next($hash,"discover"); } - if( @owx_devs == 0){ - return "OWX: No devices found "; - } #-- Check, which of these is already defined in the cfg file - foreach my $owx_dev (@owx_devs) { - #-- two pieces of the ROM ID found on the bus - my $owx_rnf = substr($owx_dev,3,12); - my $owx_f = substr($owx_dev,0,2); - my $id_owx = $owx_f.".".$owx_rnf; + foreach my $owx_dev (@owx_devs) { + #-- two pieces of the ROM ID found on the bus + my $owx_rnf = substr($owx_dev,3,12); + my $owx_f = substr($owx_dev,0,2); + my $id_owx = $owx_f.".".$owx_rnf; - my $match = 0; + my $match = 0; - #-- check against all existing devices - foreach my $fhem_dev (sort keys %main::defs) { - #-- all OW types start with OW - next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW"); - next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF"); - my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15); - #-- testing if present in defined devices - if( $id_fhem eq $id_owx ){ - push(@owx_names,$main::defs{$fhem_dev}{NAME}); - #-- replace the ROM ID by the proper value - $main::defs{$fhem_dev}{ROM_ID}=$owx_dev; - $match = 1; - last; + #-- check against all existing devices + foreach my $fhem_dev (sort keys %main::defs) { + #-- all OW types start with OW + next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW"); + next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF"); + my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15); + #-- testing if present in defined devices + if( $id_fhem eq $id_owx ){ + push(@owx_names,$main::defs{$fhem_dev}{NAME}); + #-- replace the ROM ID by the proper value + $main::defs{$fhem_dev}{ROM_ID}=$owx_dev; + $main::defs{$fhem_dev}{PRESENT}=1; + $match = 1; + last; + } } - } - #-- autocreate the device - if( $match==0 ){ - #-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF - my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf; + #-- autocreate the device + if( $match==0 ){ + #-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF + my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf; - if( $owx_f eq "10" ){ - #-- Family 10 = Temperature sensor, assume DS1820 as default - CommandDefine(undef,"$name OWTEMP DS1820 $owx_rnf"); - #-- default room - CommandAttr (undef,"$name IODev $hash->{NAME}"); - CommandAttr (undef,"$name room OWX"); - push(@owx_names,$name); - } else { - Log 1, "OWX: Undefined device family $owx_f"; + if( $owx_f eq "10" ){ + #-- Family 10 = Temperature sensor, assume DS1820 as default + CommandDefine(undef,"$name OWTEMP DS1820 $owx_rnf"); + $main::defs{$name}{PRESENT}=1; + #-- default room + CommandAttr (undef,"$name IODev $hash->{NAME}"); + CommandAttr (undef,"$name room OWX"); + push(@owx_names,$name); + } else { + Log 1, "OWX: Undefined device family $owx_f"; + } + #-- replace the ROM ID by the proper value + $main::defs{$name}{ROM_ID}=$owx_dev; } - #-- replace the ROM ID by the proper value - $main::defs{$name}{ROM_ID}=$owx_dev; } + + #-- final step: Undefine all 1-Wire devices which are not on the bus + # TODO: IF WE HAVE MULTIPLE IO Devices ??? + foreach my $fhem_dev (sort keys %main::defs) { + #-- all OW types start with OW + next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW"); + next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF"); + next if( $main::defs{$fhem_dev}{PRESENT} == 1); + CommandDelete(undef,$main::defs{$fhem_dev}{NAME}); } Log 1, "OWX: 1-Wire devices found (".join(",",@owx_names).")"; return "OWX: 1-Wire devices found (".join(",",@owx_names).")"; @@ -566,7 +575,6 @@ sub OWX_Search ($$) { $owx_LastFamilyDiscrepancy = 0; return 0; } - #print "Reset ok when starting search \n"; #-- Here we call the device dependent part if( $owx_interface eq "DS2480" ){ @@ -577,7 +585,6 @@ sub OWX_Search ($$) { Log 1,"OWX: Search called with unknown interface"; return 0; } - #--check if we really found a device if( OWX_CRC()!= 0){ #-- reset the search @@ -750,7 +757,6 @@ sub OWX_Verify ($$) { if ($dev eq $dev2){ return 1; }else{ - # print "Searching for $dev, but found $dev2\n"; return 0; } } @@ -793,8 +799,8 @@ sub OWX_Block_2480 ($$) { Log 5, "OWX_Block: OK"; return $res; } else { - Log 3, "OWX_Block: failure, length=".length($res); - return $res; + Log 3, "OWX_Block: DAS 2480 failure, received ".length($data)." bytes"; + return 0; } } @@ -890,7 +896,7 @@ sub OWX_Query_2480 ($$) { my $count_out = $owx_serport->write($cmd); Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) ); - #-- sleeping 0.03 seconds + #-- sleeping for some time select(undef,undef,undef,0.04); #-- read the data @@ -906,7 +912,7 @@ sub OWX_Query_2480 ($$) { Log 3, $res; } - #-- sleeping 0.03 seconds + #-- sleeping for some time select(undef,undef,undef,0.04); $owx_serport->close(); @@ -1123,14 +1129,16 @@ sub OWX_Block_9097 ($$) { my ($hash,$data) =@_; my $data2=""; + my $res=0; for (my $i=0; $iwrite($cmd); Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) ); - #-- sleeping 0.03 seconds - #select(undef,undef,undef,0.03); - #select(undef,undef,undef,0.05); + #-- sleeping for some time + select(undef,undef,undef,0.01); #-- read the data my ($count_in, $string_in) = $owx_serport->read(32); @@ -1195,9 +1202,8 @@ sub OWX_Query_9097 ($$) { Log 3, $res; } - #-- sleeping 0.03 seconds - #select(undef,undef,undef,0.03); - select(undef,undef,undef,0.05); + #-- sleeping for some time + select(undef,undef,undef,0.01); $owx_serport->close(); return($string_in); @@ -1408,6 +1414,7 @@ sub OWX_TouchByte_9097 ($$) { my $loop; my $result=0; + my $bytein=$byte; for( $loop=0; $loop < 8; $loop++ ){ #-- shift result to get ready for the next bit @@ -1422,6 +1429,10 @@ sub OWX_TouchByte_9097 ($$) { } $byte >>= 1; } + #print "-----------------------\n"; + #printf "Sending byte /%02x/\n",$bytein; + #printf "Receiving byte /%02x/\n",$result; + #print "-----------------------\n"; return $result; } diff --git a/contrib/1-Wire/21_OWTEMP.pm b/contrib/1-Wire/21_OWTEMP.pm index f488b7d84..2183b0214 100644 --- a/contrib/1-Wire/21_OWTEMP.pm +++ b/contrib/1-Wire/21_OWTEMP.pm @@ -16,7 +16,7 @@ # Martin Fischer, 2011 # Prof. Dr. Peter A. Henning, 2012 # -# Version 1.0 - February 21, 2012 +# Version 1.01 - February 23, 2012 # # Setup bus device in fhem.cfg as # define OWTEMP [] [interval] [alarminterval] @@ -81,7 +81,7 @@ my $scale; #"family" => "10", #"id" => "", #"locator" => "", - #"power" => "", + "interval" => "", "present" => "", "temperature" => "", "temphigh" => "", @@ -169,7 +169,7 @@ sub OWTEMP_Define ($$) { Log 1, "OWTEMP: Parameter [alarminterval] is obsolete now - must be set with I/O-Device" if(int(@a) == 6); } else { - return "OWTEMP: $a[0] hat missing ID or wrong ID format $a[2], specify a 12 digit value or set it to none for demo mode"; + return "OWTEMP: $a[0] ID $a[2] invalid, specify a 12 digit value or set it to none for demo mode"; } #-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY" @@ -287,6 +287,12 @@ sub OWTEMP_Get($@) { $value = $hash->{INTERVAL}; return "$a[0] $reading => $value"; } + + # get present + if($a[1] eq "present") { + $value = $hash->{PRESENT}; + return "$a[0] $reading => $value"; + } #-- Get other values according to interface type my $interface= $hash->{IODev}->{TYPE}; @@ -323,6 +329,7 @@ sub OWTEMP_Get($@) { $hash->{READINGS}{temphigh}{TIME} = $tn; #-- return the special reading + $reading = "temp" if( $reading eq "temperature"); if(defined($hash->{READINGS}{$reading})) { $value = $hash->{READINGS}{$reading}{VAL}; } @@ -371,6 +378,7 @@ sub OWTEMP_GetUpdate($@) { my $interface= $hash->{IODev}->{TYPE}; #-- real sensor if($hash->{OW_ID} ne "none") { + $hash->{PRESENT} = 0; #-- Get values according to interface type my $interface= $hash->{IODev}->{TYPE}; if( $interface eq "OWX" ){ @@ -516,13 +524,13 @@ sub OWTEMP_Set($@) { # # OWTEMP_Undef - Implements UndefFn function # -# Parameter hash = hash of device addressed, name +# Parameter hash = hash of device addressed # ######################################################################################## -sub OWTEMP_Undef ($$) { - my ($hash, $name) = @_; - delete($modules{OWTEMP}{defptr}{$hash->{CODE}}); +sub OWTEMP_Undef ($) { + my ($hash) = @_; + #delete($modules{OWTEMP}{defptr}{$hash->{CODE}}); RemoveInternalTimer($hash); return undef; } @@ -645,9 +653,17 @@ sub OWXTEMP_GetValues($) { if( $res eq 0 ){ return "OWXTEMP: Device $owx_dev not accessible in 2nd step"; } + my $res2 = "====> OWXTEMP Received "; + for(my $i=0;$i<19;$i++){ + my $j=int(ord(substr($res,$i,1))/16); + my $k=ord(substr($res,$i,1))%16; + $res2.=sprintf "0x%1x%1x ",$j,$k; + } + Log 1, $res2; + #-- process results my @data=split(//,$res); - if (@data == 19){ + if ( (@data == 19) && (ord($data[17])>0) ){ my $count_remain = ord($data[16]); my $count_perc = ord($data[17]); my $delta = -0.25 + ($count_perc - $count_remain)/$count_perc; @@ -660,10 +676,12 @@ sub OWXTEMP_GetValues($) { } $owg_th = ord($data[12]) > 127 ? 128-ord($data[12]) : ord($data[12]); $owg_tl = ord($data[13]) > 127 ? 128-ord($data[13]) : ord($data[13]); + + Log 1, "====> OWXTEMP Conversion result is temp = $owg_temp, delta $delta"; return undef; } else { - return "OWXTEMP: Device $owx_dev returns wrong number @data of bytes"; + return "OWXTEMP: Device $owx_dev returns invalid data"; } } diff --git a/contrib/1-Wire/Schaltplan_Passives_1-Wire_Interface.png b/contrib/1-Wire/Schaltplan_Passives_1-Wire_Interface.png index 611fb3fac..0cd477b1d 100644 Binary files a/contrib/1-Wire/Schaltplan_Passives_1-Wire_Interface.png and b/contrib/1-Wire/Schaltplan_Passives_1-Wire_Interface.png differ