Last change
on this file was 1801b32, checked in by Norbert Wigbels <njw@…>, 9 years ago |
Auf Eventmachine umgebaut
|
-
Property mode
set to
100644
|
File size:
974 bytes
|
Line | |
---|
1 | require 'pi_piper'
|
---|
2 | require 'eventmachine'
|
---|
3 |
|
---|
4 | include PiPiper
|
---|
5 |
|
---|
6 |
|
---|
7 | mypath = File.expand_path(File.dirname(__FILE__))
|
---|
8 | trigger_step = 1.0 / 96
|
---|
9 | trigger_watch = 0
|
---|
10 | counter = 0
|
---|
11 |
|
---|
12 |
|
---|
13 | def last_rrd_count(concretepath)
|
---|
14 | val = 0.0
|
---|
15 | handle = IO.popen("rrdtool lastupdate #{concretepath}")
|
---|
16 | handle.each_line do |line|
|
---|
17 | m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*")
|
---|
18 | if m
|
---|
19 | val = m[1].to_f
|
---|
20 | break
|
---|
21 | end
|
---|
22 | end
|
---|
23 | return val
|
---|
24 | end
|
---|
25 |
|
---|
26 | watch :pin => 11, :trigger => :falling do
|
---|
27 | puts('updated power consumption')
|
---|
28 | trigger_watch = 1
|
---|
29 | end
|
---|
30 |
|
---|
31 |
|
---|
32 | rrdpath = mypath + "/power.rrd"
|
---|
33 | counter = last_rrd_count(rrdpath)
|
---|
34 | puts('Counter restored to: ' + counter.to_s)
|
---|
35 |
|
---|
36 |
|
---|
37 | EventMachine.run do
|
---|
38 | EM.add_periodic_timer(1) do
|
---|
39 | if trigger_watch == 1 then
|
---|
40 | counter = counter + trigger_step
|
---|
41 | trigger_update = trigger_step * 3600000.0
|
---|
42 | system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}")
|
---|
43 | puts('Counter updated to: ' + counter.to_s)
|
---|
44 | trigger_watch = 0
|
---|
45 | end
|
---|
46 | end
|
---|
47 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.