source: de.wigbels.ruby/hothotread/hothotpiper_gas.rb@ b62bf13

Last change on this file since b62bf13 was 8cc14b9, checked in by Norbert Wigbels <njw@…>, 9 years ago

Aufraeumen

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[8cc14b9]1#!/usr/bin/env ruby
2
3require 'pi_piper'
4include PiPiper
5
6mypath = File.expand_path(File.dirname(__FILE__))
7trigger_step = 0.01
8trigger_watch = 0
9counter = 0.0
10timestamp = Time.now.to_i
11
12def last_rrd_count(concretepath)
13 val = 0.0
14 handle = IO.popen("rrdtool lastupdate #{concretepath}")
15 handle.each_line do |line|
16 m = line.match("^[0-9]*: ([0-9.]*) [0-9.]*")
17 if m
18 val = m[1].to_f
19 break
20 end
21 end
22 return val
23end
24
25watch :pin => 4, :trigger => :falling do
26 puts('triggered watch to 1')
27 trigger_watch = 1
28end
29
30rrdpath = mypath + "/gasneu.rrd"
31counter = last_rrd_count(rrdpath)
32puts('Counter restored to: '+counter.to_s)
33
34loop 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
44 end
45 sleep(1)
46end
47
Note: See TracBrowser for help on using the repository browser.