Last change
on this file was 8cc14b9, checked in by Norbert Wigbels <njw@…>, 9 years ago |
Aufraeumen
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[0955336] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | #
|
---|
| 3 | # Author: Norbert Wigbels - foobla.wigbels.de/uber-foobla
|
---|
| 4 | #
|
---|
| 5 | # HotHotPiper continously reads the status of a
|
---|
| 6 | # reed contact attached to the Raspberry Pi GPIO
|
---|
| 7 | #
|
---|
| 8 | # The reed measures gas usage.
|
---|
| 9 | #
|
---|
| 10 | # A magig URL is formed and called; the url
|
---|
| 11 | # stores the sensor-data to wigbels.net
|
---|
| 12 | #
|
---|
| 13 | # todo: status-led
|
---|
| 14 | #
|
---|
| 15 |
|
---|
| 16 | #------------------------------------------
|
---|
| 17 | # Tainted mode 0-4
|
---|
| 18 | $SAFE=0
|
---|
| 19 |
|
---|
| 20 | #------------------------------------------
|
---|
| 21 | require 'pi_piper'
|
---|
| 22 | include PiPiper
|
---|
| 23 |
|
---|
[53aed1c] | 24 | $mypath = File.expand_path(File.dirname(__FILE__))
|
---|
[daaef3e] | 25 |
|
---|
[0955336] | 26 |
|
---|
[c22952c] | 27 | def last_rrd_count
|
---|
| 28 | val = 0.0
|
---|
| 29 | handle = IO.popen("rrdtool lastupdate #{$mypath}/power.rrd")
|
---|
| 30 | handle.each_line do |line|
|
---|
| 31 | m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*")
|
---|
| 32 | if m
|
---|
| 33 | val = m[1].to_f
|
---|
| 34 | break
|
---|
| 35 | end
|
---|
| 36 | end
|
---|
| 37 | return val
|
---|
| 38 | end
|
---|
| 39 |
|
---|
| 40 |
|
---|
[0955336] | 41 | watch :pin => 4, :trigger => :falling do
|
---|
[4fd0ab9] | 42 | puts('added 10 liter of gas to sensor-database')
|
---|
[53aed1c] | 43 | system("rrdtool update #{$mypath}/gas.rrd N:10")
|
---|
[0955336] | 44 | end
|
---|
| 45 |
|
---|
[c22952c] | 46 | watch :pin => 11, :trigger => :falling do
|
---|
| 47 | puts('updated power consumption')
|
---|
| 48 | $counter = $counter + $trigger_step
|
---|
| 49 | trigger_update = $trigger_step * 3600000.0
|
---|
| 50 | system("rrdtool update #{$mypath}/power.rrd N:#{$counter}:#{trigger_update}")
|
---|
| 51 | end
|
---|
| 52 |
|
---|
| 53 | $trigger_step = 1.0 / 96
|
---|
| 54 | $counter = last_rrd_count
|
---|
| 55 |
|
---|
[0955336] | 56 | PiPiper.wait
|
---|
Note:
See
TracBrowser
for help on using the repository browser.