diff --git a/fhem/FHEM/00_NetzerI2C.pm b/fhem/FHEM/00_NetzerI2C.pm index 20944beea..1e4f37701 100644 --- a/fhem/FHEM/00_NetzerI2C.pm +++ b/fhem/FHEM/00_NetzerI2C.pm @@ -23,9 +23,10 @@ my @clients = qw( I2C_LCD I2C_DS1307 I2C_PC.* -I2C_MCP23017 +I2C_MCP23.* I2C_BMP180 I2C_SHT21 +I2C_TSL2561 ); sub NetzerI2C_Initialize($) { diff --git a/fhem/FHEM/10_FRM.pm b/fhem/FHEM/10_FRM.pm index 25f6fbde8..dec377b25 100755 --- a/fhem/FHEM/10_FRM.pm +++ b/fhem/FHEM/10_FRM.pm @@ -49,8 +49,10 @@ my @clients = qw( I2C_LCD I2C_DS1307 I2C_PC.* - I2C_MCP23017 + I2C_MCP23.* + I2C_SHT21 I2C_BMP180 + I2C_TSL2561 FRM_LCD ); diff --git a/fhem/FHEM/51_RPI_GPIO.pm b/fhem/FHEM/51_RPI_GPIO.pm index 4af47756e..ff4bc36a7 100644 --- a/fhem/FHEM/51_RPI_GPIO.pm +++ b/fhem/FHEM/51_RPI_GPIO.pm @@ -80,7 +80,7 @@ sub RPI_GPIO_Define($$) { #nix tun...ist ja schon da } elsif (-w "$gpiodir/export") { #gpio export Datei mit schreibrechten? Log3 $hash, 4, "$name: write access to file $gpiodir/export, use it to export GPIO"; - my $exp = IO::File->new("> $gpiodir/export"); #gpio ueber export anlegen + my $exp = IO::File->new("> $gpiodir/export"); #gpio ueber export anlegen print $exp "$hash->{RPI_pin}"; $exp->close; } else { @@ -93,28 +93,42 @@ sub RPI_GPIO_Define($$) { } } - # wait for Pin export (max 5s) - my $checkpath = qq($gpiodir/gpio$hash->{RPI_pin}/value); - my $counter = 100; - while( $counter ){ - last if( -e $checkpath && -w $checkpath ); - Time::HiRes::sleep( 0.05 ); - $counter --; - } - unless( $counter ) { #abbrechen wenn export fehlgeschlagen - #nochmal probieren wenn keine Schreibrechte########## - if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { #Abbbruch da kein gpio utility vorhanden - Log3 $hash, 1, "$name: can't export gpio$hash->{RPI_pin}, no write access to $gpiodir/export and " . $ret; - Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}"; - return "$name: failed to export pin gpio$hash->{RPI_pin}"; - } else { #nutze GPIO Utility? - Log3 $hash, 4, "$name: using gpio utility to export pin (first export failed)"; - RPI_GPIO_exuexpin($hash, "in"); + # wait for Pin export (max 5s) + my $checkpath = qq($gpiodir/gpio$hash->{RPI_pin}/value); + my $counter = 100; + while( $counter ){ + last if( -e $checkpath && -w $checkpath ); + Time::HiRes::sleep( 0.05 ); + $counter --; + } + unless( $counter ) { #abbrechen wenn export fehlgeschlagen + # nochmal probieren wenn keine Schreibrechte auf GPIO Dateien ########## + if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { #Abbbruch da kein gpio utility vorhanden + if ( -e "$gpiodir/export") { + Log3 $hash, 1, "$name: \"$gpiodir/export\" exists and is " . ( ( -w "$gpiodir/export") ? "" : "NOT " ) . "writable"; + } else { + Log3 $hash, 1, "$name: gpio$hash->{RPI_pin}/value doesnt exist"; } - ##################################################### -# Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}"; -# return "$name: failed to export pin gpio$hash->{RPI_pin}"; + if(-e "$gpiodir/gpio$hash->{RPI_pin}") { + Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}\" exported but define aborted:"; + if ( -e "$gpiodir/gpio$hash->{RPI_pin}/value") { + Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/value\" exists and is " . ( ( -w "$gpiodir/gpio$hash->{RPI_pin}/value") ? "" : "NOT " ) . "writable"; + } else { + Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/value\" doesnt exist"; + } + if ( -e "$gpiodir/gpio$hash->{RPI_pin}/direction") { + Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/direction\" exists and is " . ( ( -w "$gpiodir/gpio$hash->{RPI_pin}/direction") ? "" : "NOT " ) . "writable"; + } else { + Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/direction\" doesnt exist"; + } + Log3 $hash, 1, "$name: second attempt to export gpio$hash->{RPI_pin} failed: " . $ret; + } + return "$name: failed to export pin gpio$hash->{RPI_pin}, see logfile"; + } else { #nutze GPIO Utility fuer zweiten Exportversuch + Log3 $hash, 4, "$name: using gpio utility to export pin (first export via $gpiodir/export failed)"; + RPI_GPIO_exuexpin($hash, "in"); } + } $hash->{fhem}{interfaces} = "switch"; return undef; diff --git a/fhem/FHEM/52_I2C_MCP23008.pm b/fhem/FHEM/52_I2C_MCP23008.pm index a1b42abb8..d3bce8eca 100644 --- a/fhem/FHEM/52_I2C_MCP23008.pm +++ b/fhem/FHEM/52_I2C_MCP23008.pm @@ -57,7 +57,7 @@ sub I2C_MCP23008_Initialize($) { $hash->{SetFn} = "I2C_MCP23008_Set"; $hash->{GetFn} = "I2C_MCP23008_Get"; $hash->{I2CRecFn} = "I2C_MCP23008_I2CRec"; - $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0". + $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ". "poll_interval OnStartup ". "OutputPorts:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7 ". "Pullup:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7 ". diff --git a/fhem/FHEM/52_I2C_MCP23017.pm b/fhem/FHEM/52_I2C_MCP23017.pm index 90ef049e7..17519a97e 100644 --- a/fhem/FHEM/52_I2C_MCP23017.pm +++ b/fhem/FHEM/52_I2C_MCP23017.pm @@ -60,7 +60,7 @@ sub I2C_MCP23017_Initialize($) { $hash->{SetFn} = "I2C_MCP23017_Set"; $hash->{GetFn} = "I2C_MCP23017_Get"; $hash->{I2CRecFn} = "I2C_MCP23017_I2CRec"; - $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0". + $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ". "poll_interval OnStartup ". "OutputPorts:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7 ". "Pullup:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7 ". diff --git a/fhem/FHEM/52_I2C_PCA9532.pm b/fhem/FHEM/52_I2C_PCA9532.pm index 05b9b0800..b928de92b 100644 --- a/fhem/FHEM/52_I2C_PCA9532.pm +++ b/fhem/FHEM/52_I2C_PCA9532.pm @@ -46,7 +46,7 @@ sub I2C_PCA9532_Initialize($) { $hash->{SetFn} = "I2C_PCA9532_Set"; $hash->{GetFn} = "I2C_PCA9532_Get"; $hash->{I2CRecFn} = "I2C_PCA9532_I2CRec"; - $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0". + $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ". "poll_interval T0:slider,0,1,255 T1:slider,0,1,255 OnStartup InputPorts ". "OutputPorts:multiple-strict,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ". "$readingFnAttributes"; diff --git a/fhem/FHEM/52_I2C_SHT21.pm b/fhem/FHEM/52_I2C_SHT21.pm index 4c94b58ac..c1abd0980 100644 --- a/fhem/FHEM/52_I2C_SHT21.pm +++ b/fhem/FHEM/52_I2C_SHT21.pm @@ -178,13 +178,24 @@ sub I2C_SHT21_I2CRec ($$) { while ( my ( $k, $v ) = each %$clientmsg ) { #erzeugen von Internals fuer alle Keys in $clientmsg die mit dem physical Namen beginnen $hash->{$k} = $v if $k =~ /^$pname/ ; } - if ($clientmsg->{direction} && $clientmsg->{type} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok") { - if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) { - Log3 $hash, 5, "empfangen: $clientmsg->{received}"; - I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "temp" && $clientmsg->{nbyte} == 2; - I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "hum" && $clientmsg->{nbyte} == 2; - } - } + #alte Variante zur Temp Hum Unterscheidung + #if ( $clientmsg->{direction} && $clientmsg->{type} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok" ) { + # if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) { + # Log3 $hash, 5, "empfangen: $clientmsg->{received}"; + # I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "temp" && $clientmsg->{nbyte} == 2; + # I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "hum" && $clientmsg->{nbyte} == 2; + # } + #} + + # Bit 1 of the two LSBs indicates the measurement type (‘0’: temperature, ‘1’ humidity) + if ( $clientmsg->{direction} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok" ) { + if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) { + Log3 $hash, 5, "empfangen: $clientmsg->{received}"; + my @raw = split(" ",$clientmsg->{received}); + I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if !($raw[1] & 2) && $clientmsg->{nbyte} == 2; + I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if ($raw[1] & 2) && $clientmsg->{nbyte} == 2; + } + } } sub I2C_SHT21_GetTemp ($$) {