Ignore:
Timestamp:
Dec 5, 2015, 9:53:28 PM (8 years ago)
Author:
Norbert Wigbels <njw@…>
Branches:
master
Children:
8cc14b9
Parents:
b342b88
Message:

Stromzaehler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • de.wigbels.ruby/hothotread/hothotpiper.rb

    rb342b88 rc22952c  
    1919
    2020#------------------------------------------
    21 require 'net/http'
    2221require 'pi_piper'
    23 
    2422include PiPiper
    2523
     
    2725
    2826
     27def last_rrd_count
     28  val = 0.0
     29  handle = IO.popen("rrdtool lastupdate #{$mypath}/power.rrd")
     30  handle.each_line do |line|
     31    m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*")
     32    if m
     33      val = m[1].to_f
     34      break
     35    end
     36  end
     37  return val
     38end
     39
     40
    2941watch :pin => 4, :trigger => :falling do
    3042  puts('added 10 liter of gas to sensor-database')
    31   Net::HTTP.get(URI.parse('http://www.wigbels.net/cgi-bin/hhw.rb?sensorid=1&data=10'))
    3243  system("rrdtool update #{$mypath}/gas.rrd N:10")
    3344end
    3445
     46watch :pin => 11, :trigger => :falling  do
     47  puts('updated power consumption')
     48  $counter = $counter + $trigger_step
     49  trigger_update = $trigger_step * 3600000.0
     50  system("rrdtool update #{$mypath}/power.rrd N:#{$counter}:#{trigger_update}")
     51end
     52
     53$trigger_step = 1.0 / 96
     54$counter = last_rrd_count
     55
    3556PiPiper.wait
Note: See TracChangeset for help on using the changeset viewer.