Ignore:
Timestamp:
Mar 3, 2016, 11:44:50 AM (8 years ago)
Author:
Norbert Wigbels <norbert.wigbels@…>
Branches:
master
Children:
8b9b145
Parents:
7e221fe (diff), 20d3261 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of wigbels.net:/var/git/public

File:
1 edited

Legend:

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

    r7e221fe re397ced  
    11#!/usr/bin/env ruby
     2require 'pi_piper'
     3require 'eventmachine'
    24
    3 require 'pi_piper'
    45include PiPiper
     6
    57
    68mypath = File.expand_path(File.dirname(__FILE__))
     
    911counter = 0.0
    1012timestamp =  Time.now.to_i
     13
    1114
    1215def last_rrd_count(concretepath)
     
    2831end
    2932
     33
    3034rrdpath = mypath + "/gasneu.rrd"
    3135counter = last_rrd_count(rrdpath)
    32 puts('Counter restored to: '+counter.to_s)
     36puts('Counter restored to: ' + counter.to_s)
    3337
    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
     39EventMachine.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
    4451  end
    45   sleep(1)
    4652end
    4753
Note: See TracChangeset for help on using the changeset viewer.