Changeset c22952c for de.wigbels.ruby/hothotread/hothotpiper.rb
- Timestamp:
- Dec 5, 2015, 9:53:28 PM (8 years ago)
- Branches:
- master
- Children:
- 8cc14b9
- Parents:
- b342b88
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
de.wigbels.ruby/hothotread/hothotpiper.rb
rb342b88 rc22952c 19 19 20 20 #------------------------------------------ 21 require 'net/http'22 21 require 'pi_piper' 23 24 22 include PiPiper 25 23 … … 27 25 28 26 27 def 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 38 end 39 40 29 41 watch :pin => 4, :trigger => :falling do 30 42 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'))32 43 system("rrdtool update #{$mypath}/gas.rrd N:10") 33 44 end 34 45 46 watch :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}") 51 end 52 53 $trigger_step = 1.0 / 96 54 $counter = last_rrd_count 55 35 56 PiPiper.wait
Note: See TracChangeset
for help on using the changeset viewer.