diff --git a/fhem/contrib/1-Wire/00_OWX.pm b/fhem/contrib/1-Wire/00_OWX.pm index 8d9705467..0e84393cd 100644 --- a/fhem/contrib/1-Wire/00_OWX.pm +++ b/fhem/contrib/1-Wire/00_OWX.pm @@ -9,7 +9,7 @@ # Internally these interfaces are vastly different, read the corresponding Wiki pages # http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire # -# Version 2.11 - July, 2012 +# Version 2.13 - July, 2012 # # Prof. Dr. Peter A. Henning, 2012 # @@ -595,8 +595,11 @@ sub OWX_Discover ($) { my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf; #-- Family 10 = Temperature sensor, assume DS1820 as default if( $owx_f eq "10" ){ - CommandDefine(undef,"$name OWTHERM DS1820 $owx_rnf"); - #-- Family 1D = Counter/RAM, assume DS2423 as default + CommandDefine(undef,"$name OWTHERM DS1820 $owx_rnf"); + #-- Family 12 = Switch, assume DS2406 as default + }elsif( $owx_f eq "12" ){ + CommandDefine(undef,"$name OWSWITCH DS2406 $owx_rnf"); + #-- Family 1D = Counter/RAM, assume DS2423 as default }elsif( $owx_f eq "1D" ){ CommandDefine(undef,"$name OWCOUNT DS2423 $owx_rnf"); #-- Family 20 = A/D converter, assume DS2450 as default @@ -608,7 +611,7 @@ sub OWX_Discover ($) { #-- Family 28 = Temperature sensor, assume DS18B20 as default }elsif( $owx_f eq "28" ){ CommandDefine(undef,"$name OWTHERM DS18B20 $owx_rnf"); - #-- Family 3A = Switch, assume DS2413 as default + #-- Family 3A = Switch, assume DS2413 as default }elsif( $owx_f eq "3A" ){ CommandDefine(undef,"$name OWSWITCH DS2413 $owx_rnf"); #-- Family FF = LCD display diff --git a/fhem/contrib/1-Wire/21_OWAD.pm b/fhem/contrib/1-Wire/21_OWAD.pm index 8fef59490..3736c2d22 100644 --- a/fhem/contrib/1-Wire/21_OWAD.pm +++ b/fhem/contrib/1-Wire/21_OWAD.pm @@ -14,7 +14,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.11 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # diff --git a/fhem/contrib/1-Wire/21_OWCOUNT.pm b/fhem/contrib/1-Wire/21_OWCOUNT.pm index 1dfa7bbad..0f0e3686f 100644 --- a/fhem/contrib/1-Wire/21_OWCOUNT.pm +++ b/fhem/contrib/1-Wire/21_OWCOUNT.pm @@ -14,7 +14,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.11 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # diff --git a/fhem/contrib/1-Wire/21_OWID.pm b/fhem/contrib/1-Wire/21_OWID.pm index a10c4a592..56b88caa6 100644 --- a/fhem/contrib/1-Wire/21_OWID.pm +++ b/fhem/contrib/1-Wire/21_OWID.pm @@ -12,7 +12,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.11 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # diff --git a/fhem/contrib/1-Wire/21_OWLCD.pm b/fhem/contrib/1-Wire/21_OWLCD.pm index 8272c7c21..0b7534df8 100644 --- a/fhem/contrib/1-Wire/21_OWLCD.pm +++ b/fhem/contrib/1-Wire/21_OWLCD.pm @@ -12,7 +12,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.1 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # diff --git a/fhem/contrib/1-Wire/21_OWSWITCH.pm b/fhem/contrib/1-Wire/21_OWSWITCH.pm index 5d34e9b14..8bd49ccd9 100644 --- a/fhem/contrib/1-Wire/21_OWSWITCH.pm +++ b/fhem/contrib/1-Wire/21_OWSWITCH.pm @@ -2,7 +2,7 @@ # # OWSWITCH.pm # -# FHEM module to commmunicate with 1-Wire adressable switches DS2413 +# FHEM module to commmunicate with 1-Wire adressable switches DS2413, DS206 # # Attention: This module may communicate with the OWX module, # but currently not with the 1-Wire File System OWFS @@ -17,7 +17,7 @@ # # Prof. Dr. Peter A. Henning, 2012 # -# Version 2.11 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # @@ -26,7 +26,7 @@ # where may be replaced by any name string # # is a 1-Wire device type. If omitted, we assume this to be an -# DS2413 +# DS2413. Allowed values are DS2413, DS2406 # is a 12 character (6 byte) 1-Wire ROM ID # without Family ID, e.g. A2D90D000800 # [interval] is an optional query interval in seconds @@ -35,10 +35,15 @@ # get present => 1 if device present, 0 if not # get interval => query interval # get input => state for channel (name A, B or defined channel name) +# note: this value reflects the measured value, not necessarily the one set as +# output state, because the output transistors are open collector switches. A measured +# state of 1 = OFF therefore corresponds to an output state of 1 = OFF, but a measured +# state of 0 = ON can also be due to an external shortening of th eoutput. # get gpio => values for channels # # set interval => set period for measurement # set output ON|OFF => set value for channel (name A, B or defined channel name) +# note: 1 = OFF, 0 = ON in normal usage. See also th enote above # set gpio value => set values for channels (3 = both OFF, 1 = B ON 2 = A ON 0 = both ON) # # Additional attributes are defined in fhem.cfg, in some cases per channel, where =A,B @@ -46,6 +51,7 @@ # # attr Name | = name for the channel | a type description for the measured value # attr Unit | = values to display in state variable for on|off condition +# attr stateS = character string denoting external shortening condition # ######################################################################################## # @@ -76,8 +82,9 @@ sub Log($$); #-- channel name - fixed is the first array, variable the second my @owg_fixed = ("A","B"); my @owg_channel; -#-- channel values - always the raw values from the device +#-- channel values - always the raw input resp. output values from the device my @owg_val; +my @owg_vax; my %gets = ( "id" => "", @@ -124,11 +131,12 @@ sub OWSWITCH_Initialize ($) { #Offset = an offset added to the reading #Factor = a factor multiplied with (reading+offset) #Unit = a unit of measure - my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413 loglevel:0,1,2,3,4,5 "; + my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413,DS2406 loglevel:0,1,2,3,4,5 "; for( my $i=0;$i{AttrList} = $attlist; } @@ -169,21 +177,30 @@ sub OWSWITCH_Define ($$) { if(int(@a)>=4) { $interval = $a[3]; } } elsif( $a3 =~ m/^[0-9|a-f|A-F]{12}$/ ) { $model = $a[2]; - return "OWSWITCH: Wrong 1-Wire device model $model" - if( $model ne "DS2413"); $id = $a[3]; + if(int(@a)>=5) { $interval = $a[4]; } } else { return "OWSWITCH: $a[0] ID $a[2] invalid, specify a 12 digit value"; } + #-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY" + # FF = family id follows from the model + # YY must be determined from id + if( $model eq "DS2413" ){ + $fam = "3A"; + }elsif( $model eq "DS2406" ){ + $fam = "12"; + }else{ + return "OWSWITCH: Wrong 1-Wire device model $model"; + } #-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY" # determine CRC Code - only if this is a direct interface - $crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC("3A.".$id."00")) : "00"; + $crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00"; #-- Define device internals - $hash->{ROM_ID} = "3A.".$id.$crc; + $hash->{ROM_ID} = $fam.".".$id.$crc; $hash->{OW_ID} = $id; - $hash->{OW_FAMILY} = "3A"; + $hash->{OW_FAMILY} = $fam; $hash->{PRESENT} = 0; $hash->{INTERVAL} = $interval; @@ -219,12 +236,12 @@ sub OWSWITCH_InitializeDevice($) { my ($hash) = @_; my $name = $hash->{NAME}; - - #-- Initial readings - @owg_val = (0.0,0.0,0.0,0.0); #-- Set channel names, channel units for( my $i=0;$i{NAME}; - my ($offset,$factor,$vval); + my ($offset,$factor,$vval,$vvax,$vstr,$cname,@cnama,@unarr); my ($value1,$value2,$value3) = ("","",""); my $tn = TimeNow(); #-- formats for output for (my $i=0;$i{READINGS}{"$owg_channel[$i]"}{UNIT}); - $value1 .= sprintf( "%s: %s", $owg_channel[$i], $unarr[$vval]); - $value2 .= sprintf( "%s: %s ", $owg_channel[$i], $unarr[$vval]); + @unarr= split(/\|/,$hash->{READINGS}{"$owg_channel[$i]"}{UNIT}); + $cname = defined($attr{$name}{$owg_fixed[$i]."stateS"}) ? $attr{$name}{$owg_fixed[$i]."stateS"} : ""; + $vstr = $unarr[$vval]; + $vstr .= $cname if( ($vval == 0) && ($vvax == 1) ); + $vstr = "ERR" if( ($vval == 1) && ($vvax == 0) ); + + $value1 .= sprintf( "%s: %s", $owg_channel[$i], $vstr); + $value2 .= sprintf( "%s: %s ", $owg_channel[$i], $vstr); $value3 .= sprintf( "%s: " , $owg_channel[$i]); #-- put into READINGS - $hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $unarr[$vval]; + $hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vstr; $hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn; #-- insert comma @@ -457,7 +481,7 @@ sub OWSWITCH_GetValues($) { if( $interface eq "OWX" ){ $ret = OWXSWITCH_GetState($hash); #}elsif( $interface eq "OWFS" ){ - # $ret = OWFSAD_GetValues($hash); + # $ret = OWFSSWITCH_GetValues($hash); }else{ return "OWSWITCH: GetValues with wrong IODev type $interface"; } @@ -546,7 +570,7 @@ sub OWSWITCH_Set($@) { }elsif( lc($a[3]) eq "off" ){ $nval = 1; }else{ - return "OWSWITCH: Wrong data value $a[3]"; + return "OWSWITCH: Wrong data value $a[3], must be ON or OFF"; } #-- OWX interface @@ -645,48 +669,66 @@ sub OWXSWITCH_GetState($) { my $master = $hash->{IODev}; my ($i,$j,$k); - - #-- 8 byte 1-Wire device address - my @owx_ROM_ID =(0,0,0,0 ,0,0,0,0); - #-- from search string to byte id - my $devs=$owx_dev; - $devs=~s/\.//g; - for($i=0;$i<8;$i++){ - $owx_ROM_ID[$i]=hex(substr($devs,2*$i,2)); + + #-- family = 3A => DS2413 + if( $hash->{OW_FAMILY} eq "3A" ) { + #=============== get gpio values =============================== + #-- issue the match ROM command \x55 and the read gpio command + # \xF5 plus 2 empty bytes + #-- reset the bus + OWX_Reset($master); + #-- read the data + $res=OWX_Complex($master,$owx_dev,"\xF5",2); + if( $res eq 0 ){ + return "OWXSWITCH: Device $owx_dev not accessible in reading"; + } + #-- family = 12 => DS2406 + }elsif( $hash->{OW_FAMILY} eq "12" ) { + #=============== set gpio values =============================== + #-- issue the match ROM command \x55 and the access channel command + # \xF5 plus the two byte channel control and the value + $select=sprintf("\xF5\xDC\xFF"); + #-- reset the bus + OWX_Reset($master); + #-- read the data + $res=OWX_Complex($master,$owx_dev,$select,1); + if( $res eq 0 ){ + return "OWXSWITCH: Device $owx_dev not accessible in writing"; + } + } else { + return "OWXSWITCH: Unknown device family $hash->{OW_FAMILY}\n"; } - - #=============== get gpio values =============================== - #-- issue the match ROM command \x55 and the read gpio command - # \xF5 plus 2 empty bytes - #-- reset the bus - OWX_Reset($master); - #-- read the data - $res=OWX_Complex($master,$owx_dev,"\xF5",2); - if( $res eq 0 ){ - return "OWX: Device $owx_dev not accessible in reading"; - } - + #-- process results - # TODO: could we put in a check if the two bytes are equal @data=split(//,substr($res,10)); #-- reset the bus OWX_Reset($master); #my $ress = "OWXSWITCH_Get: three data bytes "; - # for($i=0;$i<3;$i++){ + # for($i=0;$i>2) % 2; - - #Log 1, "Values are ".ord($data[0])." $owg_val[0] and $owg_val[1]"; - + # note: value 1 corresponds to OFF, 0 to ON normally + # note: we display the sensed output level, not the flipflop setting + #-- family = 3A => DS2413 + if( $hash->{OW_FAMILY} eq "3A" ) { + $owg_val[0] = ord($data[0]) & 1; + $owg_vax[0] = (ord($data[0])>>1) & 1; + $owg_val[1] = (ord($data[0])>>2) & 1; + $owg_vax[1] = (ord($data[0])>>3) & 1; + + #-- family = 12 => DS2406 + }elsif( $hash->{OW_FAMILY} eq "12" ) { + $owg_val[0] = (ord($data[2])>>2) & 1; + $owg_vax[0] = ord($data[2]) & 1; + $owg_val[1] = (ord($data[2])>>3) & 1; + $owg_vax[1] = (ord($data[2])>>1) & 1; + } return undef } @@ -716,18 +758,47 @@ sub OWXSWITCH_SetState($$) { my ($i,$j,$k); - #=============== set gpio values =============================== - #-- issue the match ROM command \x55 and the write gpio command - # \x5A plus the value byte and its complement - $select=sprintf("\x5A%c%c",252+$value,3-$value); - #-- reset the bus - OWX_Reset($master); - #-- read the data - $res=OWX_Complex($master,$owx_dev,$select,1); - if( $res eq 0 ){ - return "OWX: Device $owx_dev not accessible in reading"; + #-- family = 3A => DS2413 + if( $hash->{OW_FAMILY} eq "3A" ) { + #=============== set gpio values =============================== + #-- issue the match ROM command \x55 and the write gpio command + # \x5A plus the value byte and its complement + $select=sprintf("\x5A%c%c",252+$value,3-$value); + #-- reset the bus + OWX_Reset($master); + #-- read the data + $res=OWX_Complex($master,$owx_dev,$select,1); + if( $res eq 0 ){ + return "OWXSWITCH: Device $owx_dev not accessible in writing"; + } + #-- family = 12 => DS2406 + }elsif( $hash->{OW_FAMILY} eq "12" ) { + #=============== set gpio values =============================== + # Wrriting the output state via the access channel command does + # not work contrary to documentation. Using the write status command + #-- issue the match ROM command \x55 and the read status command + # \xAA at address TA1 = \x07 TA2 = \x00 + #-- reset the bus + OWX_Reset($master); + #-- read the data + $res = OWX_Complex($master,$owx_dev,"\xAA\x07\x00",1); + my $stat = substr($res,10,1); + my $statneu = ( $stat & 159 ) | (($value<<5) & 96) ; + #-- issue the match ROM command \x55 and the write status command + # \x55 at address TA1 = \x07 TA2 = \x00 + # + $select=sprintf("\x55\x07\x00%c",$statneu); + #-- reset the bus + OWX_Reset($master); + #-- read the data + $res=OWX_Complex($master,$owx_dev,$select,2); + if( $res eq 0 ){ + return "OWXSWITCH: Device $owx_dev not accessible in writing"; + } + + } else { + return "OWXSWITCH: Unknown device family $hash->{OW_FAMILY}\n"; } - #-- reset the bus OWX_Reset($master); @@ -735,23 +806,33 @@ sub OWXSWITCH_SetState($$) { @data=split(//,substr($res,10)); #my $ress = "OWXSWITCH_Set: three data bytes "; - # for($i=0;$i<3;$i++){ + # for($i=0;$i DS2413 + if( $hash->{OW_FAMILY} eq "3A" ) { + if( $data[2] ne "\xAA"){ + return "OWXSWITCH: State could not be set for device $owx_dev"; + } + #-- family = 12 => DS2406 + }elsif( $hash->{OW_FAMILY} eq "12" ) { + #-- very crude check - should be CRC + if( int(@data) != 5){ + return "OWXSWITCH: State could not be set for device $owx_dev"; + } + } + #-- Put the new values in the system variables #-- This holds only for DS2413 $owg_val[0] = $value % 2; + $owg_vax[0] = $owg_val[0]; $owg_val[1] = int($value / 2); + $owg_vax[1] = $owg_val[1]; return undef } diff --git a/fhem/contrib/1-Wire/21_OWTHERM.pm b/fhem/contrib/1-Wire/21_OWTHERM.pm index 9f5ffcb39..a36c09a75 100755 --- a/fhem/contrib/1-Wire/21_OWTHERM.pm +++ b/fhem/contrib/1-Wire/21_OWTHERM.pm @@ -15,7 +15,7 @@ # Prof. Dr. Peter A. Henning, 2012 # Martin Fischer, 2011 # -# Version 2.12 - July, 2012 +# Version 2.13 - July, 2012 # # Setup bus device in fhem.cfg as # @@ -25,7 +25,7 @@ # # is a 1-Wire device type. If omitted, we assume this to be an # DS1820 temperature sensor -# Currently allowed values are DS1820, DS1822 +# Currently allowed values are DS1820, DS18B20, DS1822 # is a 12 character (6 byte) 1-Wire ROM ID # without Family ID, e.g. A2D90D000800 # [interval] is an optional query interval in seconds