Last change
on this file since 8cc14b9 was
8cc14b9,
checked in by Norbert Wigbels <njw@…>, 8 years ago
|
Aufraeumen
|
-
Property mode set to
100644
|
File size:
700 bytes
|
Line | |
---|
1 | require 'pi_piper' |
---|
2 | include PiPiper |
---|
3 | |
---|
4 | mypath = File.expand_path(File.dirname(__FILE__)) |
---|
5 | trigger_step = 1.0 / 96 |
---|
6 | counter = 0 |
---|
7 | |
---|
8 | def last_rrd_count(concretepath) |
---|
9 | val = 0.0 |
---|
10 | handle = IO.popen("rrdtool lastupdate #{concretepath}") |
---|
11 | handle.each_line do |line| |
---|
12 | m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*") |
---|
13 | if m |
---|
14 | val = m[1].to_f |
---|
15 | break |
---|
16 | end |
---|
17 | end |
---|
18 | return val |
---|
19 | end |
---|
20 | |
---|
21 | |
---|
22 | watch :pin => 11, :trigger => :falling do |
---|
23 | puts('updated power consumption') |
---|
24 | counter = counter + trigger_step |
---|
25 | trigger_update = trigger_step * 3600000.0 |
---|
26 | system("rrdtool update #{mypath}/power.rrd N:#{counter}:#{trigger_update}") |
---|
27 | end |
---|
28 | |
---|
29 | rrdpath = mypath + "/power.rrd" |
---|
30 | counter = last_rrd_count(rrdpath) |
---|
31 | PiPiper.wait |
---|
Note: See
TracBrowser
for help on using the repository browser.