Last change
on this file since f63674a was f38145a, checked in by Norbert Wigbels <frickel@…>, 7 years ago |
Mehr Temperaturdetails f. Kaminanalyse
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[2c75e95] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | require 'pi_piper'
|
---|
| 3 | require 'eventmachine'
|
---|
| 4 |
|
---|
| 5 | include PiPiper
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | mypath = File.expand_path(File.dirname(__FILE__))
|
---|
[05062c9] | 9 | trigger_step = 0.001
|
---|
[2c75e95] | 10 | trigger_watch = 0
|
---|
| 11 | counter = 0.0
|
---|
| 12 | timestamp = Time.now.to_i
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | def last_rrd_count(concretepath)
|
---|
| 16 | val = 0.0
|
---|
| 17 | handle = IO.popen("rrdtool lastupdate #{concretepath}")
|
---|
| 18 | handle.each_line do |line|
|
---|
| 19 | m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*")
|
---|
| 20 | if m
|
---|
| 21 | val = m[1].to_f
|
---|
| 22 | break
|
---|
| 23 | end
|
---|
| 24 | end
|
---|
| 25 | return val
|
---|
| 26 | end
|
---|
| 27 |
|
---|
[f38145a] | 28 | watch :pin => 9, :trigger => :rising do
|
---|
[2c75e95] | 29 | puts('triggered watch to 1')
|
---|
| 30 | trigger_watch = 1
|
---|
| 31 | end
|
---|
| 32 |
|
---|
| 33 |
|
---|
[05062c9] | 34 | rrdpath = mypath + "/water.rrd"
|
---|
[f38145a] | 35 | #counter = last_rrd_count(rrdpath)
|
---|
[2c75e95] | 36 | puts('Counter restored to: ' + counter.to_s)
|
---|
| 37 |
|
---|
| 38 | EventMachine.run do
|
---|
| 39 | EM.add_periodic_timer(1) do
|
---|
| 40 | if trigger_watch == 1 then
|
---|
| 41 | counter = counter + trigger_step
|
---|
[f38145a] | 42 | #system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_step}")
|
---|
[2c75e95] | 43 | puts('Counter updated to: ' + counter.to_s)
|
---|
| 44 | timestamp = Time.now.to_i
|
---|
| 45 | trigger_watch = 0
|
---|
| 46 | elsif Time.now.to_i - timestamp > 3600
|
---|
[f38145a] | 47 | # system("rrdtool update #{rrdpath} N:#{counter}:0")
|
---|
[2c75e95] | 48 | timestamp = Time.now.to_i
|
---|
| 49 | end
|
---|
| 50 | end
|
---|
| 51 | end
|
---|
| 52 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.