require 'pi_piper' include PiPiper mypath = File.expand_path(File.dirname(__FILE__)) trigger_step = 1.0 / 96 counter = 0 def last_rrd_count(concretepath) val = 0.0 handle = IO.popen("rrdtool lastupdate #{concretepath}") handle.each_line do |line| m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*") if m val = m[1].to_f break end end return val end watch :pin => 11, :trigger => :falling do puts('updated power consumption') counter = counter + trigger_step trigger_update = trigger_step * 3600000.0 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}") end rrdpath = mypath + "/power.rrd" counter = last_rrd_count(rrdpath) PiPiper.wait