diff --git a/fhem/FHEM/51_RPI_GPIO.pm b/fhem/FHEM/51_RPI_GPIO.pm
index ff4bc36a7..3c7083029 100644
--- a/fhem/FHEM/51_RPI_GPIO.pm
+++ b/fhem/FHEM/51_RPI_GPIO.pm
@@ -36,6 +36,7 @@ sub RPI_GPIO_Initialize($) {
" interrupt:none,falling,rising,both" .
" toggletostate:no,yes active_low:no,yes" .
" debounce_in_ms restoreOnStartup:no,yes,on,off,last" .
+ " unexportpin:no,yes" .
" longpressinterval " .
"$readingFnAttributes";
}
@@ -353,28 +354,27 @@ sub RPI_GPIO_Attr(@) {
$msg = "$hash->{NAME}: debounce_in_ms value to big. Use 0 to 250";
}
}
- if ($attr eq 'pud_resistor') {#nur fuer Raspberry (ueber gpio utility)
- my $pud;
- if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) {
- Log3 $hash, 1, "$hash->{NAME}: unable to change pud resistor:" . $ret;
- return "$hash->{NAME}: " . $ret;
- } else {
- if ( !$val ) {
- } elsif ($val eq "off") {
- $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' tri';
- $pud = `$pud`;
- } elsif ($val eq "up") {
- $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' up';
- $pud = `$pud`;
- } elsif ($val eq "down") {
- $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' down';
- $pud = `$pud`;
- } else {
- $msg = "$hash->{NAME}: Wrong $attr value. Use off, up or down";
- }
- }
- }
- return ($msg) ? $msg : undef;
+ if ($attr eq "pud_resistor" && $val) {
+ if($val =~ /^(off|up|down)$/) {
+ if(-w "$gpiodir/gpio$hash->{RPI_pin}/pull") {
+ $val =~ s/off/disable/;
+ RPI_GPIO_fileaccess($hash, "pull", $val);
+ } else { #nur fuer Raspberry (ueber gpio utility)
+ my $pud;
+ if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) {
+ Log3 $hash, 1, "$hash->{NAME}: unable to change pud resistor:" . $ret;
+ return "$hash->{NAME}: " . $ret;
+ } else {
+ $val =~ s/off/tri/;
+ $pud = $gpioprg." -g mode ".$hash->{RPI_pin}." ".$val;
+ $pud = `$pud`;
+ }
+ }
+ } else {
+ $msg = "$hash->{NAME}: Wrong $attr value. Use off, up or down";
+ }
+ }
+ return ($msg) ? $msg : undef;
}
sub RPI_GPIO_Poll($) { #for attr poll_intervall -> readout pin value
@@ -397,13 +397,17 @@ sub RPI_GPIO_Undef($$) {
delete $selectlist{$hash->{NAME}};
close($hash->{filehandle});
}
- if (-w "$gpiodir/unexport") {#unexport Pin alte Version
+ # to have a chance to externaly setup the GPIOs -
+ # leave GPIOs untouched if attr unexportpin is set to "no"
+ if(AttrVal($hash->{NAME},"unexportpin","") ne "no") {
+ if (-w "$gpiodir/unexport") {#unexport Pin alte Version
my $uexp = IO::File->new("> $gpiodir/unexport");
print $uexp "$hash->{RPI_pin}";
$uexp->close;
- } else {#alternative unexport Pin:
+ } else {#alternative unexport Pin:
RPI_GPIO_exuexpin($hash, "unexport");
- }
+ }
+ }
Log3 $hash, 1, "$hash->{NAME}: entfernt";
return undef;
}
@@ -651,7 +655,7 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling
In addition to the Raspberry Pi, also BBB, Cubie, Banana Pi and almost every linux system which provides gpio access in userspace is supported.
Warning: Never apply any external voltage to an output configured pin! GPIO's internal logic operate with 3,3V. Don't exceed this Voltage!
preliminary:
- GPIO Pins accessed by sysfs. The files are located in folder /system/class/gpio and belong to the gpio group (on actual Raspbian distributions since jan 2014).
+ GPIO Pins accessed by sysfs. The files are located in folder /system/class/gpio and belong to the gpio group (on actual Raspbian distributions since jan 2014). It will work even on an Jessie version but NOT if you perform an kerlen update
After execution of following commands, GPIO's are usable whithin PRI_GPIO:
sudo adduser fhem gpio
@@ -675,7 +679,7 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling
echo 23 > /sys/class/gpio/export
chown -R fhem:root /sys/devices/virtual/gpio/* (or chown -R fhem:gpio /sys/devices/platform/gpio-sunxi/gpio/* for Banana Pi)
chown -R fhem:root /sys/class/gpio/*
- /system/class/gpio und sind in der aktuellen Raspbian Distribution (ab Jan 2014) in der Gruppe gpio./system/class/gpio und sind in der aktuellen Raspbian Distribution (ab Jan 2014) in der Gruppe gpio. Es funktioniert auch mit der Jessie Version. Allerdings NICHT wenn ein Kernelupgrade durchgeführt wird
sudo adduser fhem gpio
@@ -1001,6 +1009,10 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling
Wartezeit in ms bis nach ausgelöstem Interrupt der entsprechende Pin abgefragt wird. Kann zum entprellen von mechanischen Schaltern verwendet werden
Standard: 0, gültige Werte: Dezimalzahl
+ - unexportpin
+ Führe unexport über /sys/class/gpio/unexport aus wenn die Pin-Definition gelöscht wird (z.B. durch rereadcfg, delete,...)
+ Standard: yes, , gültige Werte: yes, no
+
- restoreOnStartup
Wiederherstellen der Portzustände nach Neustart
Standard: last, gültige Werte: last, on, off, no
diff --git a/fhem/FHEM/53_GHoma.pm b/fhem/FHEM/53_GHoma.pm
index ac48c4f35..3f0f219ba 100644
--- a/fhem/FHEM/53_GHoma.pm
+++ b/fhem/FHEM/53_GHoma.pm
@@ -133,7 +133,7 @@ sub GHoma_ClientDisconnect($$) { # im Mom unnuetz
#####################################
sub GHoma_Shutdown($) { #
my ($hash) = @_;
- return unless defined $hash->{Id};
+ return unless defined $hash->{Id}; #nicht für Server
# state auf letzten Schaltwert setzen oder auf fixen Startwert (wird bereitsbeim Shutdown ausgefuehrt)
if (AttrVal($hash->{NAME},"restoreOnStartup","last") eq "on") {
readingsSingleUpdate($hash, "state", "on", 1);
@@ -148,7 +148,7 @@ sub GHoma_Shutdown($) { #
sub GHoma_Define($$$) { #
my ($hash, $def) = @_;
- my @a = split("[ \t][ \t]*", $def);
+ #my @a = split("[ \t][ \t]*", $def);
my ($name, $type, $pport, $global) = split("[ \t]+", $def);
my $port = $pport;
@@ -161,12 +161,12 @@ sub GHoma_Define($$$) { #
#return "Usage: define GHoma { [IPV6:]| }" if(!($isServer || $isClient || $isSerCli));
return "Usage: define GHoma { [IPV6:] }" if(!($isServer || $isClient || $isSerCli));
- $hash->{DeviceName} = $pport;
-
+ #$hash->{DeviceName} = $pport;
if($isSerCli) { #ServerClient
- my $name = $a[0];
- my $addr = $a[2];
- $hash->{Id} = pack('C*', ( hex(substr($addr,0,2)), hex(substr($addr,2,2)), hex(substr($addr,4,2)) ) );
+ #my $name = $a[0];
+ # my $addr = $a[2];
+ #$hash->{Id} = pack('C*', ( hex(substr($pport,0,2)), hex(substr($pport,2,2)), hex(substr($pport,4,2)) ) );
+ $hash->{Id} = $pport;
return;
}
@@ -247,7 +247,7 @@ sub GHoma_Read($) { # wird von der globalen loop aufgerufen (ueber $hash->{F
return;
}
- if ( substr($buf,0,10) eq ($prefix . $dosehb )) { # Heartbeat
+ if ( substr($buf,0,10) eq ($prefix . $dosehb )) { # Heartbeat (Dosen Id wird nicht ueberprueft)
#DevIo_SimpleWrite($hash, GHoma_BuildString($hbeat) , undef);
RemoveInternalTimer($hash);
$buf =~ s/(.|\n)/sprintf("%.2X ",ord($1))/eg; #empfangene Zeichen in Hexwerte wandeln
@@ -275,9 +275,10 @@ sub GHoma_Read($) { # wird von der globalen loop aufgerufen (ueber $hash->{F
Log3 $hash, 5, "$hash->{NAME} RX: 5A A5 $smsg"; # ...und ins Log schreiben
if ( substr($_,2,6) eq ($cinit1)) { # Antwort auf erstes Init
- $hash->{Id} = substr($_,8,3);
+ #$hash->{Id} = substr($_,8,3);
+ $hash->{Id} = unpack('H*', substr($_,8,3) );
unless ($hash->{isClient}) {
- # fuer Server Loesung bei erster Antwort von Dose nach bestehendem Devicem it gleicher Id suchen und Verbindung auf dieses Modul uebertragen
+ # fuer Server Loesung bei erster Antwort von Dose nach bestehendem Device mit gleicher Id suchen und Verbindung auf dieses Modul uebertragen
my $clientdefined = undef;
foreach my $dev (devspec2array("TYPE=$hash->{TYPE}")) { # bereits bestehendes define mit dieser Id suchen
if ($hash->{Id} eq InternalVal($dev,"Id","") && $hash->{NAME} ne $dev && InternalVal($dev,"TEMPORARY","") ne "1") {
@@ -288,10 +289,13 @@ sub GHoma_Read($) { # wird von der globalen loop aufgerufen (ueber $hash->{F
}
}
unless ( defined $clientdefined) { # ...ein Neues anlegen, falls keins existiert
- my $id = unpack('H*', $hash->{Id} );
- Log3 $name, 4, "GHoma Unknown device $id, please define it";
- DoTrigger("global", "UNDEFINED GHoma_$id GHoma $id");
- GHoma_moveclient($hash, $defs{"GHoma_$id"}) if ($defs{"GHoma_$id"});
+ #my $id = unpack('H*', $hash->{Id} );
+ #Log3 $name, 4, "GHoma Unknown device $id, please define it";
+ #DoTrigger("global", "UNDEFINED GHoma_$id GHoma $id");
+ #GHoma_moveclient($hash, $defs{"GHoma_$id"}) if ($defs{"GHoma_$id"});
+ Log3 $name, 4, "GHoma Unknown device $hash->{Id}, please define it";
+ DoTrigger("global", "UNDEFINED GHoma_$hash->{Id} GHoma $hash->{Id}");
+ GHoma_moveclient($hash, $defs{"GHoma_$hash->{Id}"}) if ($defs{"GHoma_$hash->{Id}"});
}
} else {
readingsSingleUpdate($hash, "state", "Initialize...", 1);
@@ -390,7 +394,7 @@ sub GHoma_Set($@) { #
return SetExtensions($hash, $slist, @a);
}
if (defined $hash->{CD}) {
- syswrite( $hash->{CD}, GHoma_BuildString($switch1 . $hash->{Id} . $switch2 . $type) );
+ syswrite( $hash->{CD}, GHoma_BuildString($switch1 . pack('C*', ( hex(substr($hash->{Id},0,2)), hex(substr($hash->{Id},2,2)), hex(substr($hash->{Id},4,2)) ) ) . $switch2 . $type) );
}
return undef;
}
@@ -398,7 +402,7 @@ sub GHoma_Set($@) { #
sub GHoma_State($$$$) { # reload readings at FHEM start
my ($hash, $tim, $sname, $sval) = @_;
Log3 $hash, 4, "$hash->{NAME}: $sname kann auf $sval wiederhergestellt werden $tim";
- if ( $sname eq "state" && defined $hash->{Id} ) {
+ if ( $sname eq "state" && defined $hash->{Id} ) { #wenn kein Server
$hash->{LASTSTATE} = $sval;
readingsSingleUpdate($hash, "state", "offline", 1)
}