mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-12 02:39:57 +00:00
added new module 51_BBB_BMP180
git-svn-id: https://svn.fhem.de/fhem/trunk@4033 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ad40dd7526
commit
9cfbfde8d1
@ -1,6 +1,7 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
|
||||
- 2013-xx-xx (SVN)
|
||||
- feature: new module 51_BBB_BMP180.pm added (betateilchen)
|
||||
- feature: readingsGroup: allow devStateIcon to be displayed
|
||||
- feature: readingsGroup: allow multiple device readings in one line
|
||||
- feature: YAMAHA_AVR - new remoteControl commands for Tuner Preset
|
||||
|
299
fhem/FHEM/51_BBB_BMP180.pm
Normal file
299
fhem/FHEM/51_BBB_BMP180.pm
Normal file
@ -0,0 +1,299 @@
|
||||
# $Id:
|
||||
####################################################################################################
|
||||
#
|
||||
# 51_BBB_BMP180.pm
|
||||
#
|
||||
# An FHEM Perl module for reading air pressure from BMP180 sensor connected on I2C
|
||||
#
|
||||
# Please read commandref for details on prerequisits!
|
||||
#
|
||||
# Copyright: betateilchen ®
|
||||
# e-mail: fhem.development@betateilchen.de
|
||||
#
|
||||
# This file is part of fhem.
|
||||
#
|
||||
# Fhem is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Fhem 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
####################################################################################################package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use feature qw/say switch/;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub BBB_BMP180_Define($$);
|
||||
sub BBB_BMP180_Undefine($$);
|
||||
sub BBB_BMP180_Get($@);
|
||||
sub BBB_BMP180_Attr($@);
|
||||
|
||||
# $next = gettimeofday()+$hash->{helper}{INTERVAL};
|
||||
# readingsSingleUpdate($hash, "c_nextUpdate", localtime($next), 1);
|
||||
# InternalTimer($next, "GDS_GetUpdate", $hash, 1);
|
||||
|
||||
sub BBB_BMP180_Initialize($){
|
||||
my ($hash) = @_;
|
||||
$hash->{DefFn} = "BBB_BMP180_Define";
|
||||
$hash->{UndefFn} = "BBB_BMP180_Undefine";
|
||||
$hash->{GetFn} = "BBB_BMP180_Get";
|
||||
$hash->{AttrFn} = "BBB_BMP180_Attr";
|
||||
$hash->{AttrList} = "bbbRoundPressure:0,1 bbbRoundTemperature:0,1 ".
|
||||
"bbbInterval ".
|
||||
$readingFnAttributes;
|
||||
}
|
||||
|
||||
sub BBB_BMP180_Define($$){
|
||||
my ($hash, $def) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
Log3($name, 3, "BBB_BMP180 $name: created");
|
||||
readingsSingleUpdate($hash, "state", "active",1);
|
||||
|
||||
$hash->{helper}{i2cbus} = '1';
|
||||
$hash->{helper}{i2cbus} = $a[2] if(defined($a[2]));
|
||||
|
||||
my $next = gettimeofday()+10;
|
||||
InternalTimer($next, "bbb_getValues", $hash, 0);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub BBB_BMP180_Undefine($$){
|
||||
my($hash, $name) = @_;
|
||||
RemoveInternalTimer($hash);
|
||||
return;
|
||||
}
|
||||
|
||||
sub BBB_BMP180_Get($@){
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my ($cmd) = $a[1];
|
||||
|
||||
my $usage = "Unknown argument $cmd, choose one of readValues:noArg";
|
||||
return $usage if($cmd eq "?");
|
||||
|
||||
given($cmd) {
|
||||
|
||||
when("readValues") {
|
||||
bbb_getValues($hash,1);
|
||||
}
|
||||
|
||||
default {return}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub BBB_BMP180_Attr($@){
|
||||
my @a = @_;
|
||||
my $hash = $defs{$a[1]};
|
||||
my (undef, $name, $attrName, $attrValue) = @a;
|
||||
given($attrName){
|
||||
when("bbbInterval"){
|
||||
RemoveInternalTimer($hash);
|
||||
my $next = gettimeofday()+$attrValue;
|
||||
InternalTimer($next, "bbb_getValues", $hash, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
default {$attr{$name}{$attrName} = $attrValue;}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
sub bbb_getValues($$){
|
||||
my ($hash,$local) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $a = AttrVal('global','altitude',undef);
|
||||
my $t = bbb_temp($hash);
|
||||
my $pa = bbb_absDruck($hash);
|
||||
my $pr = bbb_relDruck($hash,$a) if(defined($a));
|
||||
|
||||
if(AttrVal($name,'bbbRoundPressure',undef)){
|
||||
$pa = sprintf("%.0f", $pa);
|
||||
$pr = sprintf("%.0f", $pr) if(defined($a));
|
||||
} else {
|
||||
$pa = sprintf("%.2f", $pa);
|
||||
$pr = sprintf("%.2f", $pr) if(defined($a));
|
||||
}
|
||||
|
||||
if(AttrVal($name,'bbbRoundTemperature',undef)){
|
||||
$t = sprintf("%.0f", $t);
|
||||
} else {
|
||||
$t = sprintf("%.1f", $t);
|
||||
}
|
||||
|
||||
my $s = "T: $t P: $pa";
|
||||
$s .= " P-nn: $pr" if(defined($a));
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, 'temperature', $t);
|
||||
readingsBulkUpdate($hash, 'pressure', $pa);
|
||||
readingsBulkUpdate($hash, 'pressure-nn', $pr) if(defined($a));
|
||||
readingsBulkUpdate($hash, 'state', $s) if(defined($a));
|
||||
readingsEndUpdate($hash, 1);
|
||||
|
||||
my $next = gettimeofday()+AttrVal($name,'bbbInterval',300);
|
||||
InternalTimer($next, "bbb_getValues", $hash, 0) unless $local;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub bbb_temp($){
|
||||
my ($hash) = @_;
|
||||
my $bmpT = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/temp0_input';
|
||||
my $temp;
|
||||
|
||||
open (IN,"<$bmpT") || die $!;
|
||||
while (<IN>){
|
||||
$temp = $_;
|
||||
last;
|
||||
}
|
||||
close IN;
|
||||
|
||||
$temp = substr($temp,0,length($temp)-1);
|
||||
|
||||
return $temp/10;
|
||||
}
|
||||
|
||||
sub bbb_absDruck($){
|
||||
my ($hash) = @_;
|
||||
my $bmpP = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/pressure0_input';
|
||||
my $p;
|
||||
|
||||
open (IN,"<$bmpP") || die $!;
|
||||
while (<IN>){
|
||||
$p = $_;
|
||||
last;
|
||||
}
|
||||
close IN;
|
||||
|
||||
$p = substr($p,0,length($p)-1);
|
||||
|
||||
return $p/100;
|
||||
}
|
||||
|
||||
sub bbb_relDruck($$){
|
||||
my($hash,$Alti) = @_;
|
||||
my $Pa = bbb_absDruck($hash);
|
||||
my $Temp = bbb_temp($hash);
|
||||
|
||||
# Konstanten
|
||||
my $g0 = 9.80665;
|
||||
my $R = 287.05;
|
||||
my $T = 273.15;
|
||||
my $Ch = 0.12;
|
||||
my $a = 0.065;
|
||||
my $E = 0;
|
||||
|
||||
if($Temp < 9.1){
|
||||
$E = 5.6402*(-0.0916 + exp(0.06 * $Temp));
|
||||
}
|
||||
else {
|
||||
$E = 18.2194*(1.0463 - exp(-0.0666 * $Temp));
|
||||
}
|
||||
|
||||
my $xp = $Alti * $g0 / ($R*($T+$Temp + $Ch*$E + $a*$Alti/2));
|
||||
my $Pr = $Pa*exp($xp);
|
||||
|
||||
return $Pr;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=begin html
|
||||
|
||||
<a name="BBB_BMP180"></a>
|
||||
<h3>BBB_BMP180</h3>
|
||||
<ul>
|
||||
|
||||
<b>Prerequesits</b>
|
||||
<ul>
|
||||
<br/>
|
||||
Module was developed for use with Beaglebone Black, but can be used on other platforms, too.<br/><br/>
|
||||
To create the device, run the following command on system console:<br/><br/>
|
||||
<code>echo bmp085 0x77 > /sys/class/i2c-adapter/i2c-1/new_device</code><br/><br/>
|
||||
To check if successful:<br/><br/>
|
||||
<code>
|
||||
dmesg | grep bmp<br/>
|
||||
[ 76.989945] i2c i2c-1: new_device: Instantiated device bmp085 at 0x77<br/>
|
||||
[ 77.040606] bmp085 1-0077: Successfully initialized bmp085!<br/>
|
||||
</code>
|
||||
<br/>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<a name="BBB_BMP180define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<br/>
|
||||
<code>define <name> BBB_BMP180 [bus]</code>
|
||||
<br/><br/>
|
||||
This module provides air pressure measurement by a BMP180 sensor connected to I2C bus.<br/>
|
||||
Optional parameter [bus] defines number of I2C-bus in your hardware (default = 1).<br/>
|
||||
If you want to use this module with RaspberryPi, you should set bus number to 0.<br/>
|
||||
<br/>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<a name="BBB_BMP180set"></a>
|
||||
<b>Set-Commands</b><br/>
|
||||
<ul>
|
||||
<br/>
|
||||
No set commands implemented.<br/>
|
||||
<br/>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<a name="BBB_BMP180get"></a>
|
||||
<b>Get-Commands</b><br/>
|
||||
<ul>
|
||||
<br/>
|
||||
<code>get <name> readValues</code>
|
||||
<br/><br/>
|
||||
<ul>
|
||||
Update all values immediately.
|
||||
</ul>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<a name="BBB_BMP180attr"></a>
|
||||
<b>Attributes</b><br/><br/>
|
||||
<ul>
|
||||
<li><b>bbbInterval</b> - Interval for readings update (default = 300 seconds)</li>
|
||||
<li><b>bbbRoundPressure</b> - If set to 1 = pressure value will be presented without decimals (default = 2 decimals)</li>
|
||||
<li><b>bbbRoundTemperatue</b> - If set to 1 = temperature value will be presented without decimals (default = 1 decimal)</li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Generated Readings/Events:</b>
|
||||
<br/><br/>
|
||||
<ul>
|
||||
<li><b>temperature</b> - temperature at sensor</li>
|
||||
<li><b>pressure</b> - pressure (absolute)</li>
|
||||
<li><b>pressure-nn</b> - pressure (relative), global attribute altitude needed for calculation</li>
|
||||
</ul>
|
||||
<br/><br/>
|
||||
|
||||
<b>Author's notes</b><br/><br/>
|
||||
<ul>
|
||||
<li>Have fun!</li><br/>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
@ -104,8 +104,9 @@ FHEM/46_TRX_SECURITY.pm wherzig http://forum.fhem.de RFXTRX
|
||||
FHEM/46_TRX_WEATHER.pm wherzig http://forum.fhem.de RFXTRX
|
||||
FHEM/49_IPCAM.pm mfr69bs http://forum.fhem.de Sonstiges
|
||||
FHEM/50_WS300.pm Dirk http://forum.fhem.de SlowRF
|
||||
FHEM/51_I2C_BMP180.pm Dirk http://forum.fhem.de/ Raspberry Pi
|
||||
FHEM/55_GDS.pm betateilchen http://forum.fhem.de Unterstützende Dienste
|
||||
FHEM/51_BBB_BMP180.pm betateilchen http://forum.fhem.de Raspberry Pi
|
||||
FHEM/51_I2C_BMP180.pm Dirk http://forum.fhem.de Raspberry Pi
|
||||
FHEM/55_GDS.pm betateilchen http://forum.fhem.de Unterstuetzende Dienste
|
||||
FHEM/55_PIFACE.pm betateilchen http://forum.fhem.de Raspberry Pi
|
||||
FHEM/56_POKEYS.pm axelberner http://forum.fhem.de Sonstiges
|
||||
FHEM/57_Calendar.pm borisneubert http://forum.fhem.de Sonstiges
|
||||
|
Loading…
x
Reference in New Issue
Block a user