Changeset 1801b32
- Timestamp:
- 12/09/2015 07:47:17 PM (9 years ago)
- Branches:
- master
- Children:
- 7fbafc7
- Parents:
- b62bf13
- Location:
- de.wigbels.ruby
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
de.wigbels.ruby/hothotread/hothotpiper_gas.rb
rb62bf13 r1801b32 1 1 #!/usr/bin/env ruby 2 require 'pi_piper' 3 require 'eventmachine' 2 4 3 require 'pi_piper'4 5 include PiPiper 6 5 7 6 8 mypath = File.expand_path(File.dirname(__FILE__)) … … 9 11 counter = 0.0 10 12 timestamp = Time.now.to_i 13 11 14 12 15 def last_rrd_count(concretepath) … … 28 31 end 29 32 33 30 34 rrdpath = mypath + "/gasneu.rrd" 31 35 counter = last_rrd_count(rrdpath) 32 puts('Counter restored to: ' +counter.to_s)36 puts('Counter restored to: ' + counter.to_s) 33 37 34 loop do 35 if trigger_watch == 1 then 36 counter = counter + trigger_step 37 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_step}") 38 puts('Counter updated to: '+counter.to_s) 39 timestamp = Time.now.to_i 40 trigger_watch = 0 41 elsif Time.now.to_i - timestamp > 3600 42 system("rrdtool update #{rrdpath} N:#{counter}:0") 43 timestamp = Time.now.to_i 38 39 EventMachine.run do 40 EM.add_periodic_timer(1) do 41 if trigger_watch == 1 then 42 counter = counter + trigger_step 43 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_step}") 44 puts('Counter updated to: ' + counter.to_s) 45 timestamp = Time.now.to_i 46 trigger_watch = 0 47 elsif Time.now.to_i - timestamp > 3600 48 system("rrdtool update #{rrdpath} N:#{counter}:0") 49 timestamp = Time.now.to_i 50 end 44 51 end 45 sleep(1)46 52 end 47 53 -
de.wigbels.ruby/hothotread/hothotpiper_power.rb
rb62bf13 r1801b32 1 1 require 'pi_piper' 2 require 'eventmachine' 3 2 4 include PiPiper 5 3 6 4 7 mypath = File.expand_path(File.dirname(__FILE__)) 5 8 trigger_step = 1.0 / 96 9 trigger_watch = 0 6 10 counter = 0 11 7 12 8 13 def last_rrd_count(concretepath) … … 19 24 end 20 25 21 22 26 watch :pin => 11, :trigger => :falling do 23 27 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}") 28 trigger_watch = 1 27 29 end 30 28 31 29 32 rrdpath = mypath + "/power.rrd" 30 33 counter = last_rrd_count(rrdpath) 31 PiPiper.wait 34 puts('Counter restored to: ' + counter.to_s) 35 36 37 EventMachine.run do 38 EM.add_periodic_timer(1) do 39 if trigger_watch == 1 then 40 counter = counter + trigger_step 41 trigger_update = trigger_step * 3600000.0 42 system("rrdtool update #{rrdpath} N:#{counter}:#{trigger_update}") 43 puts('Counter updated to: ' + counter.to_s) 44 trigger_watch = 0 45 end 46 end 47 end
Note:
See TracChangeset
for help on using the changeset viewer.