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