mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-13 11:16:36 +00:00
Bugfix: negative temp and internal re-design
git-svn-id: https://svn.fhem.de/fhem/trunk@2400 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a4040bf0b2
commit
a9261a9866
@ -1,18 +1,27 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# GPIO4.pm written by Peter J. Flathmann #
|
#
|
||||||
# Version 0.3, 2012-12-16 #
|
# $Id$
|
||||||
# #
|
#
|
||||||
# define RPi GPIO4 BUSMASTER #
|
# Copyright notice
|
||||||
# #
|
#
|
||||||
# All devices should be automatically created with model information: #
|
# (c) 2012 Copyright: Peter J. Flathmann (peter dot flathmann at web dot de)
|
||||||
# =================================================================== #
|
# All rights reserved
|
||||||
# define mysSensor GPIO4 28-000004715a10 #
|
#
|
||||||
# attr mySensor model DS18B20 #
|
# This script free software; you can redistribute it and/or modify
|
||||||
# #
|
# it under the terms of the GNU General Public License as published by
|
||||||
# Optional attributes: #
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# ==================== #
|
# (at your option) any later version.
|
||||||
# attr mySensor pollingInterval 60 (default: 60s) #
|
#
|
||||||
# #
|
# The GNU General Public License can be found at
|
||||||
|
# http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||||
|
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||||
|
#
|
||||||
|
# This script is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
@ -27,10 +36,20 @@ sub GPIO4_Initialize($) {
|
|||||||
|
|
||||||
$hash->{DefFn} = "GPIO4_Define";
|
$hash->{DefFn} = "GPIO4_Define";
|
||||||
$hash->{UndefFn} = "GPIO4_Undef";
|
$hash->{UndefFn} = "GPIO4_Undef";
|
||||||
|
$hash->{NotifyFn} = "GPIO4_Notify";
|
||||||
$hash->{GetFn} = "GPIO4_Get";
|
$hash->{GetFn} = "GPIO4_Get";
|
||||||
$hash->{AttrList} = "tempOffset pollingInterval model loglevel:0,1,2,3,4,5,6";
|
$hash->{AttrList} = "tempOffset pollingInterval model loglevel:0,1,2,3,4,5,6";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub GPIO4_Notify($$) {
|
||||||
|
my ($hash, $dev) = @_;
|
||||||
|
return if($hash->{DEF} ne "BUSMASTER" || $dev->{NAME} ne "global" || !grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
|
||||||
|
# check bus for new devices not before fhem.cfg completely loaded to avoid duplicates
|
||||||
|
GPIO4_GetSlaves($hash);
|
||||||
|
delete $modules{GPIO4}{NotifyFn};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sub GPIO4_Define($$) {
|
sub GPIO4_Define($$) {
|
||||||
|
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
@ -39,23 +58,18 @@ sub GPIO4_Define($$) {
|
|||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
return "syntax: define <name> GPIO4 <id>|BUSMASTER" if (int(@a) != 3);
|
return "syntax: define <name> GPIO4 <id>|BUSMASTER" if (int(@a) != 3);
|
||||||
$hash->{NAME} = $a[0];
|
$hash->{NAME} = $a[0];
|
||||||
$hash->{TYPE} = $a[1];
|
$hash->{TYPE} = 'GPIO4';
|
||||||
|
|
||||||
if ($a[2] eq "BUSMASTER") {
|
if ($a[2] eq "BUSMASTER") {
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
|
|
||||||
# check connected devices after fhem.cfg completely loaded to avoid duplicates (5s)
|
|
||||||
InternalTimer(gettimeofday()+5, "GPIO4_GetSlaves", $hash, 0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my ($family, $id) = split('-',$a[2]);
|
my ($family, $id) = split('-',$a[2]);
|
||||||
if ($family eq "28" || $family eq "10") {
|
if ($family eq "28" || $family eq "10") {
|
||||||
|
|
||||||
# reset failures counter
|
# reset failures counter
|
||||||
setReadingsVal($hash,'failures',0,TimeNow());
|
setReadingsVal($hash,'failures',0,TimeNow());
|
||||||
|
$hash->{fhem}{interfaces} = "temperature";
|
||||||
# start polling device after fhem.cfg completely loaded to ensure pollingInterval attribute is assigned (5s)
|
GPIO4_DeviceUpdateLoop($hash);
|
||||||
InternalTimer(gettimeofday()+5, "GPIO4_DeviceUpdateLoop", $hash, 0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "GPIO4: device family $family not supported";
|
return "GPIO4: device family $family not supported";
|
||||||
@ -88,35 +102,17 @@ sub GPIO_GetSlave($$) {
|
|||||||
return if (exists $defs{$devicename}{DEF} && $defs{$devicename}{DEF} eq $slave);
|
return if (exists $defs{$devicename}{DEF} && $defs{$devicename}{DEF} eq $slave);
|
||||||
}
|
}
|
||||||
|
|
||||||
# device does not exist, create it
|
# device does not exist, let autocreate create it
|
||||||
Log 1, "GPIO4: create $slave";
|
my $model;
|
||||||
CommandDefine(undef,"gpio4_$id GPIO4 $slave");
|
|
||||||
if ($family eq "28") {
|
if ($family eq "28") {
|
||||||
$attr{"gpio4_$id"}{model} = "DS18B20";
|
$model = "DS18B20";
|
||||||
}
|
}
|
||||||
if ($family eq "10") {
|
elsif ($family eq "10") {
|
||||||
$attr{"gpio4_$id"}{model} = "DS1820";
|
$model = "DS1820";
|
||||||
}
|
}
|
||||||
$attr{"gpio4_$id"}{room} = "GPIO4";
|
DoTrigger("global", "UNDEFINED GPIO4_${model}_${id} GPIO4 $slave");
|
||||||
$defs{"gpio4_$id"}{MASTER} = $hash->{NAME};
|
$attr{"GPIO4_${model}_${id}"}{model} = $model;
|
||||||
|
|
||||||
# create logfile temp4:Temp
|
|
||||||
my @logfile = split('/',$attr{autocreate}{filelog});
|
|
||||||
pop(@logfile);
|
|
||||||
my $logdir = join('/',@logfile);
|
|
||||||
CommandDefine(undef,"FileLog_gpio4_$id FileLog $logdir/gpio4_$id-%Y.log gpio4_$id:T:.*");
|
|
||||||
$attr{"FileLog_gpio4_$id"}{room} = "GPIO4";
|
|
||||||
$attr{"FileLog_gpio4_$id"}{logtype} = "temp4:Temp,text";
|
|
||||||
|
|
||||||
# create plot
|
|
||||||
if ($attr{autocreate}{weblink}) {
|
|
||||||
CommandDefine(undef,"weblink_gpio4_$id weblink fileplot FileLog_gpio4_$id:temp4:CURRENT");
|
|
||||||
$attr{"weblink_gpio4_$id"}{label} = '"'."gpio4_$id: ".'Min $data{min1}, Max $data{max1}, Last $data{currval1}"';
|
|
||||||
$attr{"weblink_gpio4_$id"}{room} = $attr{autocreate}{weblink_room} || "GPIO4";
|
|
||||||
}
|
|
||||||
|
|
||||||
# save fhem.cfg depending on autocreate autosave
|
|
||||||
CommandSave(undef, undef) if($attr{autocreate}{autosave});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +130,7 @@ sub GPIO4_Get($) {
|
|||||||
Log 6, "GPIO4: GPIO4_Get($hash->{NAME})";
|
Log 6, "GPIO4: GPIO4_Get($hash->{NAME})";
|
||||||
open DATA, "/sys/bus/w1/devices/$hash->{DEF}/w1_slave";
|
open DATA, "/sys/bus/w1/devices/$hash->{DEF}/w1_slave";
|
||||||
if (<DATA> =~ /YES/) {
|
if (<DATA> =~ /YES/) {
|
||||||
<DATA> =~ /t=(\d+)/;
|
<DATA> =~ /t=(-?\d+)/;
|
||||||
my $temp = $1/1000.0;
|
my $temp = $1/1000.0;
|
||||||
if ($attr{$hash->{NAME}}{tempOffset}) {
|
if ($attr{$hash->{NAME}}{tempOffset}) {
|
||||||
$temp+=$attr{$hash->{NAME}}{tempOffset};
|
$temp+=$attr{$hash->{NAME}}{tempOffset};
|
||||||
@ -160,3 +156,74 @@ sub GPIO4_Undef($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
=pod
|
||||||
|
=begin html
|
||||||
|
|
||||||
|
<a name="GPIO4"></a>
|
||||||
|
<h3>GPIO4</h3>
|
||||||
|
<ul>
|
||||||
|
1-wire temperature sensors connected to Raspberry Pi's GPIO port 4.
|
||||||
|
<br><br>
|
||||||
|
<a name="GPIO4define"></a>
|
||||||
|
<b>Define</b>
|
||||||
|
<ul>
|
||||||
|
<code>define <name> GPIO4 ('BUSMASTER'|<id>)</code>
|
||||||
|
<br><br>
|
||||||
|
Defines the BUSMASTER or one of the slave devices. The BUSMASTER is necessary
|
||||||
|
to get the slaves automatically created by autocreate.pm.
|
||||||
|
<br><br>
|
||||||
|
Examples:
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define RPi GPIO4 BUSMASTER<br>
|
||||||
|
define mysSensor GPIO4 28-000004715a10<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<a name="GPIO4attr"></a>
|
||||||
|
<b>Attributes</b>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#pollingInterval">pollingInterval</a></li>
|
||||||
|
<li><a href="#tempOffest">tempOffset</a></li>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
=end html
|
||||||
|
=begin html_DE
|
||||||
|
|
||||||
|
<a name="GPIO4"></a>
|
||||||
|
<h3>GPIO4</h3>
|
||||||
|
<ul>
|
||||||
|
1-wire Temperatursensoren an GPIO Port 4 des Raspberry Pi.
|
||||||
|
<br><br>
|
||||||
|
<a name="GPIO4define"></a>
|
||||||
|
<b>Define</b>
|
||||||
|
<ul>
|
||||||
|
<code>define <name> GPIO4 ('BUSMASTER'|<id>)</code>
|
||||||
|
<br><br>
|
||||||
|
Definiert den BUSMASTER oder die Slave-Devices. Der BUSMASTER ist notwendig,
|
||||||
|
um die Slave-Devices automatisch via autocreate.pm zu erzeugen.
|
||||||
|
<br><br>
|
||||||
|
Examples:
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define RPi GPIO4 BUSMASTER<br>
|
||||||
|
define mysSensor GPIO4 28-000004715a10<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<a name="GPIO4attr"></a>
|
||||||
|
<b>Attributes</b>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#pollingInterval">pollingInterval</a></li>
|
||||||
|
<li><a href="#tempOffest">tempOffset</a></li>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
=end html_DE
|
||||||
|
=cut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user