source: de.wigbels.ruby/hothotread/hothotpiper_power.rb @ b62bf13

Last change on this file since b62bf13 was b62bf13, checked in by Norbert Wigbels <njw@…>, 8 years ago

Path, Gasverbrauch

  • Property mode set to 100644
File size: 691 bytes
Line 
1require 'pi_piper'
2include PiPiper
3
4mypath = File.expand_path(File.dirname(__FILE__))
5trigger_step = 1.0 / 96
6counter = 0
7
8def 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
19end
20
21
22watch :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 #{rrdpath} N:#{counter}:#{trigger_update}")
27end
28
29rrdpath = mypath + "/power.rrd"
30counter = last_rrd_count(rrdpath)
31PiPiper.wait
Note: See TracBrowser for help on using the repository browser.