hardware:channels:meters:water:ohne_s0
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
hardware:channels:meters:water:ohne_s0 [2015/12/31 16:12] – angelegt mikemiller | hardware:channels:meters:water:ohne_s0 [2015/12/31 17:00] (aktuell) – mikemiller | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | + | Siehe [[hardware: | |
- | + | ||
- | Idee: Das kleine Sternrad des Wasserzählers mit einem Laser anvisieren. | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | Den Laser gibt es im Zehnerpack bei Ebay ab 2,50: | + | |
- | [[http:// | + | |
- | + | ||
- | Das ganze habe ich mit einer BPW34 [[http:// | + | |
- | Als Schaltung habe ich das hier gewählt: | + | |
- | + | ||
- | [[https:// | + | |
- | + | ||
- | Halterung ist ein abgesägtes Stück graues PVC-Rohr. Abgesägt ist das Stück, wo normalerweise die Dichtung drin ist. | + | |
- | Darauf ist ein Aluminium Flachprofil geschraubt. | + | |
- | + | ||
- | So sieht es aus, wenn es fertig ist: | + | |
- | + | ||
- | {{:hardware: | + | |
- | + | ||
- | Neben dem Wasserzähler greife ich auch den Gaszähler ab. Auf dem letzten Rädchen ist hier ein silber beschichtetets Stück, das hervoragend reflektiert. Hier musste ich nicht den Aufwand mit dem Laser machen, sondern nutze hier dieses Bauteil [[http:// | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | Beide Zähler gehen an einen Analog in eines Arduino V3 (Ebay, deutlich unter 10 Euro) [[http:// | + | |
- | + | ||
- | + | ||
- | Das ist der Code auf dem Arduino. Die Idee ist die Differenz zwischen dem Tal und dem Berg bei dem analogen Sensort als Trigger zu verwenden | + | |
- | + | ||
- | <code c> | + | |
- | + | ||
- | //sets ground pin to LOW and input pin to HIGH | + | |
- | void setup() | + | |
- | { | + | |
- | Serial.begin(38400); | + | |
- | // | + | |
- | digitalWrite(A1, | + | |
- | } | + | |
- | long wasser_counter = 0; | + | |
- | long gas_counter = 0; | + | |
- | int wasser_max = 0; | + | |
- | int gas_max = 0; | + | |
- | int wasser = 0; | + | |
- | int gas = 0; | + | |
- | int wasser_z = 0; | + | |
- | int gas_z = 0; | + | |
- | unsigned long lastlog = 0; | + | |
- | unsigned long time; | + | |
- | + | ||
- | void loop() | + | |
- | { | + | |
- | int gas = analogRead(1); | + | |
- | int wasser = analogRead(0); | + | |
- | + | ||
- | wasser_max = max(wasser_max, | + | |
- | gas_max = max(gas_max, | + | |
- | + | ||
- | if ((wasser_max - 400) > wasser | + | |
- | { | + | |
- | wasser_z++; | + | |
- | } else { | + | |
- | wasser_z = 0; | + | |
- | } | + | |
- | + | ||
- | if ((gas_max - 110) > gas ) | + | |
- | { | + | |
- | gas_z++; | + | |
- | } else { | + | |
- | gas_z = 0; | + | |
- | } | + | |
- | + | ||
- | if (gas_z > 100){ | + | |
- | gas_counter++; | + | |
- | gas_max= 0; | + | |
- | } | + | |
- | + | ||
- | if (wasser_z > 100){ | + | |
- | wasser_counter++; | + | |
- | wasser_max= 0; | + | |
- | } | + | |
- | time = millis(); | + | |
- | + | ||
- | if (time - lastlog > 1000){ | + | |
- | // Serial.print(" | + | |
- | lastlog = time; | + | |
- | long checksum = time + gas + gas_counter + wasser + wasser_counter; | + | |
- | + | ||
- | + | ||
- | Serial.print(time); | + | |
- | Serial.print(" | + | |
- | Serial.print(gas); | + | |
- | Serial.print(" | + | |
- | Serial.print(gas_counter); | + | |
- | Serial.print(" | + | |
- | Serial.print(wasser); | + | |
- | Serial.print(" | + | |
- | Serial.print(wasser_counter); | + | |
- | Serial.print(" | + | |
- | Serial.print(checksum); | + | |
- | Serial.print(" | + | |
- | Serial.print(gas_max); | + | |
- | Serial.print(" | + | |
- | Serial.println(wasser_max); | + | |
- | + | ||
- | } | + | |
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | Der Code auf der PC/ | + | |
- | <code perl> | + | |
- | # | + | |
- | # Set up the serial port | + | |
- | use DBI; | + | |
- | #use LWP:: | + | |
- | use Time::HiRes qw(usleep nanosleep time); | + | |
- | + | ||
- | my $dbh2 = DBI-> | + | |
- | my $sth3 = $dbh2-> | + | |
- | #my $Gas_offset | + | |
- | #my $wasser_offset = | + | |
- | + | ||
- | system(" | + | |
- | my $dbh = DBI-> | + | |
- | my $sth = $dbh-> | + | |
- | my $sth2 = $dbh-> | + | |
- | $sth2-> | + | |
- | + | ||
- | #1014 | + | |
- | + | ||
- | open(LOGGING, | + | |
- | open(SERIAL, | + | |
- | while (1) { | + | |
- | # Poll to see if any data is coming in | + | |
- | # | + | |
- | eval { | + | |
- | local $SIG{ALRM} = sub { die " | + | |
- | + | ||
- | # alarm(x) muss in den eval()-Block | + | |
- | alarm(10); | + | |
- | $test = < | + | |
- | alarm(0); | + | |
- | + | ||
- | }; ## end of eval | + | |
- | + | ||
- | # Irgendetwas schiefgelaufen? | + | |
- | if ($@) { | + | |
- | print " | + | |
- | die(); | + | |
- | } | + | |
- | + | ||
- | elsif (length($test)==0){ | + | |
- | print " | + | |
- | sleep 20; | + | |
- | die(); | + | |
- | } | + | |
- | + | ||
- | + | ||
- | + | ||
- | if ( $test =~ /([0-9]*) - ([0-9]*) - ([0-9]*) - ([0-9]*) - ([0-9]*) - ([0-9]*) - ([0-9]*) - ([0-9]*)/ && $1 + $2 + $3 + $4 + $5 == $6){ | + | |
- | $gas = $2; | + | |
- | $gas_counter = $3; | + | |
- | $wasser = $4; | + | |
- | $wasser_counter = $5; | + | |
- | $sth-> | + | |
- | + | ||
- | if ($wasser_counter > $wasser_counter_old){ | + | |
- | $sth3-> | + | |
- | + | ||
- | } | + | |
- | $wasser_counter_old = $wasser_counter; | + | |
- | if ($gas_counter > $gas_counter_old){ | + | |
- | $sth3-> | + | |
- | + | ||
- | } | + | |
- | $gas_counter_old = $gas_counter; | + | |
- | chop($test); | + | |
- | chop($test); | + | |
- | print LOGGING $test.`date`; | + | |
- | print $test.`date`; | + | |
- | } | + | |
- | + | ||
- | + | ||
- | + | ||
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | Was noch justiert werden muss, ist die Differenz, die zwischen Tal und Berg nötig ist: | + | |
- | + | ||
- | <code php> | + | |
- | <?php | + | |
- | //include ("/ | + | |
- | //include ("/ | + | |
- | include ("/ | + | |
- | include ("/ | + | |
- | include ("/ | + | |
- | + | ||
- | $graph = new Graph(3000, | + | |
- | $graph-> | + | |
- | + | ||
- | // | + | |
- | // | + | |
- | $graph-> | + | |
- | $graph-> | + | |
- | # | + | |
- | // | + | |
- | $graph-> | + | |
- | $graph-> | + | |
- | $graph-> | + | |
- | $graph-> | + | |
- | $graph-> | + | |
- | + | ||
- | + | ||
- | $connection = mysql_connect(" | + | |
- | $db_selected = mysql_select_db(" | + | |
- | if (!$connection) | + | |
- | { | + | |
- | die(' | + | |
- | } | + | |
- | if (!$db_selected) | + | |
- | { | + | |
- | die(' | + | |
- | } | + | |
- | $query = " | + | |
- | $result = mysql_query($query); | + | |
- | $i=0; | + | |
- | while ($row = @mysql_fetch_assoc($result)) | + | |
- | { | + | |
- | $ywert[$i] = $row[' | + | |
- | + | ||
- | $stunden[$i] = $row[' | + | |
- | $i +=1; | + | |
- | } | + | |
- | + | ||
- | $lineplot=new LinePlot($ywert, | + | |
- | $lineplot-> | + | |
- | + | ||
- | $graph-> | + | |
- | $graph-> | + | |
- | + | ||
- | ?> | + | |
- | + | ||
- | + | ||
- | </ | + | |
- | + | ||
- | + | ||
- | So sieht so eine Grafik aus: | + | |
- | + | ||
- | + | ||
- | {{: | + | |
hardware/channels/meters/water/ohne_s0.txt · Zuletzt geändert: 2015/12/31 17:00 von mikemiller