feuchtigkeitssensor
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
feuchtigkeitssensor [2016/09/07 21:29] – [Die Vorbereitungen] der_vitti | feuchtigkeitssensor [2018/04/01 16:03] (aktuell) – Titel jau | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== 1-Wire Feuchtigkeitssensor ====== | + | ===(verschobene Seite)=== |
- | + | #redirect | |
- | Dr. Claus Kühnel beschreibt eine Möglichkeit, | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | Tobias Müller hat unter [[http:// | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | Bei Bedarf kann man die passenden Platinen, einen Bausatz oder gleich eine fertig gelötete Version bei Tobias käuflich erwerben: | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | ===== HIH-5030 ===== | + | |
- | + | ||
- | Der HIH-5030, | + | |
- | [[http:// | + | |
- | ]] | + | |
- | + | ||
- | + | ||
- | ===== DS-2438 ===== | + | |
- | + | ||
- | Smart Battery Monitor: | + | |
- | [[http:// | + | |
- | + | ||
- | ===== Die Vorbereitungen ===== | + | |
- | Folgende Perl Module werden verwendet und müssen ggf. nachinstalliert werden: | + | |
- | * LWP:: | + | |
- | < | + | |
- | + | ||
- | ===== Das Script ===== | + | |
- | + | ||
- | < | + | |
- | # | + | |
- | + | ||
- | # Created 2014.09.13 | + | |
- | # Version: 1.1 2014.09.14 | + | |
- | # Based on Allan Dyers 1Wire Humidity script at http:// | + | |
- | # If someone else also become annoyed because of the really looong running | + | |
- | # time of this script | + | |
- | # in C (not like me) please take although a look at | + | |
- | # http:// | + | |
- | + | ||
- | use warnings; | + | |
- | use strict; | + | |
- | use Digest:: | + | |
- | use LWP:: | + | |
- | use Log:: | + | |
- | + | ||
- | my @alldevs; | + | |
- | my $onewire | + | |
- | my $VZURL | + | |
- | + | ||
- | my $opt_d | + | |
- | + | ||
- | my $name; | + | |
- | my $onewireaddress; | + | |
- | my $uuid; | + | |
- | my $temp; | + | |
- | my $humidity; | + | |
- | + | ||
- | + | ||
- | ###### | + | |
- | # $OFF $FATAL | + | |
- | # | + | |
- | + | ||
- | # Initialize logging | + | |
- | my $log_conf = q( | + | |
- | log4perl.appender.Screen=Log:: | + | |
- | log4perl.appender.Screen.stderr=0 | + | |
- | log4perl.appender.Screen.Threshold=FATAL | + | |
- | log4perl.appender.Screen.layout=Log:: | + | |
- | log4perl.appender.Email=Log:: | + | |
- | log4perl.appender.Email.smtp=spamcheck.pop-siegen.de | + | |
- | log4perl.appender.Email.subject=1Wire Humidity Read Script | + | |
- | log4perl.appender.Email.to=1whumidity_script@oktasilan.de | + | |
- | log4perl.appender.Email.from=1wirehumidity@oktasilan.de | + | |
- | log4perl.appender.Email.Threshold=WARN | + | |
- | log4perl.appender.Email.layout=Log:: | + | |
- | log4perl.rootLogger=WARN, | + | |
- | log4perl.appender.LOGFILE=Log:: | + | |
- | log4perl.appender.LOGFILE.filename=/var/log/1w_humidity.log | + | |
- | log4perl.appender.LOGFILE.mode=append | + | |
- | log4perl.appender.LOGFILE.layout=PatternLayout | + | |
- | log4perl.appender.LOGFILE.layout.ConversionPattern=[%d %r] %p %F Line: %L %M %c - %m%n | + | |
- | ); | + | |
- | Log:: | + | |
- | my $log = Log:: | + | |
- | $log-> | + | |
- | + | ||
- | + | ||
- | # welche werte sollen geholt werden? | + | |
- | my %Daten = ( # Name => [ Adresse onewire, uuid-Volkszaehler ] | + | |
- | " | + | |
- | " | + | |
- | ); | + | |
- | my $start_run = time(); | + | |
- | + | ||
- | + | ||
- | use Fcntl qw(: | + | |
- | my $lockfile = '/tmp/ | + | |
- | sub BailOut { | + | |
- | $log-> | + | |
- | exit(1); | + | |
- | } | + | |
- | + | ||
- | $log-> | + | |
- | open(my $fhpid, '>', | + | |
- | flock($fhpid, | + | |
- | # Note: lock should be automatically released at end of program, | + | |
- | # no matter how the process is terminated. (the file persists, only the lock will be removed) | + | |
- | + | ||
- | while (($name) = each(%Daten)){ | + | |
- | $onewireaddress = $Daten{$name}[0] ; | + | |
- | $log-> | + | |
- | ($Daten{$name}[2], | + | |
- | + | ||
- | $uuid | + | |
- | $temp | + | |
- | $humidity = $Daten{$name}[3] ; | + | |
- | + | ||
- | if ($humidity) { | + | |
- | $log-> | + | |
- | + | ||
- | my $server_endpoint = $VZURL . " | + | |
- | $log-> | + | |
- | # set custom HTTP request header fields | + | |
- | my $req = HTTP:: | + | |
- | $req-> | + | |
- | $req-> | + | |
- | + | ||
- | # add POST data to HTTP request body | + | |
- | $req-> | + | |
- | + | ||
- | my $ua = LWP:: | + | |
- | my $resp = $ua-> | + | |
- | if ($resp-> | + | |
- | my $message = $resp-> | + | |
- | $log-> | + | |
- | } else { | + | |
- | $log-> | + | |
- | $log-> | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | my $end_run = time(); | + | |
- | my $run_time = $end_run - $start_run; | + | |
- | $log-> | + | |
- | + | ||
- | sub DS2438reader { | + | |
- | my ($devf) = @_; | + | |
- | my $rtime= time; | + | |
- | $log-> | + | |
- | unless (open( DS2438, " | + | |
- | # | + | |
- | return; | + | |
- | } | + | |
- | my $oldfh = select DS2438; $|= 1; select $oldfh; # autoflush | + | |
- | my ($status, $vad, $vdd, $temp, $humid); | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | ($status, $temp, $vad)= readTVC(); | + | |
- | return unless defined($vad); | + | |
- | if ($status) { | + | |
- | print STDERR " | + | |
- | return; | + | |
- | } | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | for (my $b=" | + | |
- | print DS2438 " | + | |
- | ($status, $temp, $vdd)= readTVC(); | + | |
- | return unless defined($vdd); | + | |
- | if ($status ^ 0x08) { | + | |
- | print STDERR " | + | |
- | return; | + | |
- | } | + | |
- | if ($vad == $vdd) { | + | |
- | # | + | |
- | $log-> | + | |
- | return; | + | |
- | } | + | |
- | # | + | |
- | $humid= ($vad / $vdd - 0.1515) / 0.00636 / (1.0546 - 0.00216 * $temp); | + | |
- | $log-> | + | |
- | + | ||
- | # return { temp => $temp, humid => $humid, time => (time - $rtime) }; | + | |
- | return $temp, | + | |
- | + | ||
- | } | + | |
- | + | ||
- | sub readTVC { | + | |
- | my $data; | + | |
- | read DS2438, $data, 9; # and CRC | + | |
- | my ($status, $t, $v, $c, $th, $crc) = unpack(' | + | |
- | # | + | |
- | $log-> | + | |
- | unless (crcCheck(substr($data, | + | |
- | # | + | |
- | $log-> | + | |
- | return; | + | |
- | } | + | |
- | my $temp = ($t >> 3) * 0.03125; | + | |
- | $log-> | + | |
- | return $status, $temp, $v; | + | |
- | } | + | |
- | + | ||
- | sub crcCheck { | + | |
- | # Dallas/ | + | |
- | my ($r, $c) = @_; | + | |
- | my $ctx = Digest:: | + | |
- | $ctx-> | + | |
- | my $crc= $ctx-> | + | |
- | if ($opt_d) { | + | |
- | my @data = unpack(' | + | |
- | $log-> | + | |
- | } | + | |
- | $log-> | + | |
- | return (ord($c) == $crc); | + | |
- | } | + | |
- | </ | + | |
- | + |
feuchtigkeitssensor.1473276593.txt.gz · Zuletzt geändert: 2016/09/07 21:29 von der_vitti