msg-flukso-localinterface 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/msg-flukso-currentwatts +91 -0
- data/bin/msg-flukso-discover +144 -0
- data/lib/msg-flukso-localinterface.rb +6 -0
- data/lib/msg-flukso-localinterface/discover.rb +45 -0
- data/lib/msg-flukso-localinterface/query.rb +43 -0
- metadata +75 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "msg-flukso-localinterface"
|
8
|
+
gem.summary = %Q{Displays various information from the mySmartGrid project on your Chumby}
|
9
|
+
gem.description = %Q{The mySmartGrid project provides means to manage your household energy consumption. This gem provides the runtime environment for the Chumby: it queries the mySmartGrid webservice and forwards that information to a Flash application running on the Chumby.}
|
10
|
+
gem.email = "md@gonium.net"
|
11
|
+
gem.homepage = "http://github.com/gonium/msg-flukso-localinterface"
|
12
|
+
gem.authors = ["Mathias Dalheimer"]
|
13
|
+
#gem.add_dependency "xml-simple", ">= 1.0.12"
|
14
|
+
gem.bindir='bin'
|
15
|
+
gem.executables=['msg-flukso-discover', 'msg-flukso-currentwatts']
|
16
|
+
gem.default_executable = 'msg-flukso-discover'
|
17
|
+
gem.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "msg-chumby-display #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
###
|
3
|
+
##
|
4
|
+
# msg-flukso-localinterface: A Ruby library for the Local Flukso
|
5
|
+
# Interface
|
6
|
+
# Copyright (C) 2010 Mathias Dalheimer (md@gonium.net)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License along
|
19
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
21
|
+
##
|
22
|
+
###
|
23
|
+
|
24
|
+
libpath=File.join(File.dirname(__FILE__), '..', 'lib')
|
25
|
+
$:.unshift << libpath
|
26
|
+
#puts "Using libraty path #{$:.join(":")}"
|
27
|
+
|
28
|
+
require 'msg-flukso-localinterface'
|
29
|
+
require 'optparse'
|
30
|
+
require 'ostruct'
|
31
|
+
|
32
|
+
###
|
33
|
+
## Commandline parser
|
34
|
+
#
|
35
|
+
class Optparser
|
36
|
+
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
37
|
+
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
38
|
+
#
|
39
|
+
# Return a structure describing the options.
|
40
|
+
#
|
41
|
+
def self.parse(args)
|
42
|
+
# The options specified on the command line will be collected in *options*.
|
43
|
+
# We set default values here.
|
44
|
+
options = OpenStruct.new
|
45
|
+
options.inplace = false
|
46
|
+
options.encoding = "utf8"
|
47
|
+
options.verbose = false
|
48
|
+
opts = OptionParser.new do |opts|
|
49
|
+
opts.banner = "Usage: #{$0} [options]"
|
50
|
+
opts.separator ""
|
51
|
+
opts.separator "Specific options:"
|
52
|
+
opts.on("-t", "--timerange VALUE", "The time range you want to query. Valid queries are: {hour, day, month, year, night}") do |timerange|
|
53
|
+
options.timerange = timerange
|
54
|
+
end
|
55
|
+
opts.on("-u", "--unit VALUE", "The unit you want to query. Valid queries are: {watt, kwh, eur, aud}") do |unit|
|
56
|
+
options.unit = unit
|
57
|
+
end
|
58
|
+
opts.on("-c", "--config FILE", "The file where the configuration lives.") do |file|
|
59
|
+
options.config_file = file
|
60
|
+
end
|
61
|
+
# Boolean switch.
|
62
|
+
opts.on("-v", "--verbose", "Run verbosely") do |v|
|
63
|
+
options.verbose = v
|
64
|
+
end
|
65
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
66
|
+
puts opts
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
opts.parse!(args)
|
71
|
+
options
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
###
|
76
|
+
## Script startup
|
77
|
+
#
|
78
|
+
options = Optparser.parse(ARGV)
|
79
|
+
$verbose = options.verbose
|
80
|
+
|
81
|
+
# TODO: Discover Flukso dynamically.
|
82
|
+
discoveryMechanism=FluksoLocal::DiscoverStaticConfiguration.new("192.168.1.102", 80);
|
83
|
+
location=discoveryMechanism.getFluksoLocation();
|
84
|
+
puts "Using Flukso at location #{location}"
|
85
|
+
|
86
|
+
# Now: Query the Flukso.
|
87
|
+
query=FluksoLocal::Query.new(location)
|
88
|
+
values=query.getReadings("d69779ec53a9323b695ee86b5328dd28");
|
89
|
+
puts "Retrieved #{values.size} seconds of data";
|
90
|
+
last_value=values.max
|
91
|
+
puts "Last reading: timestamp = #{last_value[0]}, value=#{last_value[1]}"
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
###
|
3
|
+
##
|
4
|
+
# msg-flukso-localinterface: A Ruby library for the Local Flukso
|
5
|
+
# Interface
|
6
|
+
# Copyright (C) 2010 Mathias Dalheimer (md@gonium.net)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License along
|
19
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
21
|
+
##
|
22
|
+
###
|
23
|
+
|
24
|
+
libpath=File.join(File.dirname(__FILE__), '..', 'lib')
|
25
|
+
$:.unshift << libpath
|
26
|
+
#puts "Using libraty path #{$:.join(":")}"
|
27
|
+
|
28
|
+
require 'msg-flukso-localinterface'
|
29
|
+
require 'optparse'
|
30
|
+
require 'ostruct'
|
31
|
+
|
32
|
+
###
|
33
|
+
## Commandline parser
|
34
|
+
#
|
35
|
+
class Optparser
|
36
|
+
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
37
|
+
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
38
|
+
#
|
39
|
+
# Return a structure describing the options.
|
40
|
+
#
|
41
|
+
def self.parse(args)
|
42
|
+
# The options specified on the command line will be collected in *options*.
|
43
|
+
# We set default values here.
|
44
|
+
options = OpenStruct.new
|
45
|
+
options.inplace = false
|
46
|
+
options.encoding = "utf8"
|
47
|
+
options.verbose = false
|
48
|
+
opts = OptionParser.new do |opts|
|
49
|
+
opts.banner = "Usage: #{$0} [options]"
|
50
|
+
opts.separator ""
|
51
|
+
opts.separator "Specific options:"
|
52
|
+
opts.on("-t", "--timerange VALUE", "The time range you want to query. Valid queries are: {hour, day, month, year, night}") do |timerange|
|
53
|
+
options.timerange = timerange
|
54
|
+
end
|
55
|
+
opts.on("-u", "--unit VALUE", "The unit you want to query. Valid queries are: {watt, kwh, eur, aud}") do |unit|
|
56
|
+
options.unit = unit
|
57
|
+
end
|
58
|
+
opts.on("-c", "--config FILE", "The file where the configuration lives.") do |file|
|
59
|
+
options.config_file = file
|
60
|
+
end
|
61
|
+
# Boolean switch.
|
62
|
+
opts.on("-v", "--verbose", "Run verbosely") do |v|
|
63
|
+
options.verbose = v
|
64
|
+
end
|
65
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
66
|
+
puts opts
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
opts.parse!(args)
|
71
|
+
options
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
###
|
76
|
+
## Script startup
|
77
|
+
#
|
78
|
+
options = Optparser.parse(ARGV)
|
79
|
+
$verbose = options.verbose
|
80
|
+
|
81
|
+
# this is how the interface should look like, its a stub only right now.
|
82
|
+
discoveryMechanism=FluksoLocal::Discover.new();
|
83
|
+
location=discoveryMechanism.getFluksoLocation();
|
84
|
+
puts location
|
85
|
+
|
86
|
+
# This is some test to see how it can be done. HOWL seems to be easier,
|
87
|
+
# though.
|
88
|
+
|
89
|
+
require 'dnssd'
|
90
|
+
require 'socket'
|
91
|
+
#require 'resolv-replace' # async DNS resolving.
|
92
|
+
|
93
|
+
#service = DNSSD::Service.new
|
94
|
+
#begin
|
95
|
+
#timeout 6 do
|
96
|
+
# service.browse '_http._tcp' do |r|
|
97
|
+
# puts "Found HTTP service: #{r.name}"
|
98
|
+
# end
|
99
|
+
#end
|
100
|
+
#rescue Timeout::Error
|
101
|
+
#end
|
102
|
+
|
103
|
+
|
104
|
+
# Browse the network for web servers (_http._tcp services)
|
105
|
+
puts "Scanning network for web servers"
|
106
|
+
service = DNSSD.browse('_flukso-realtime._tcp.') do |reply|
|
107
|
+
if (reply.flags == DNSSD::Flags::Add)
|
108
|
+
puts "adding: #{reply.inspect}"
|
109
|
+
|
110
|
+
# Let's lookup the details
|
111
|
+
resolver_service = DNSSD.resolve(reply.name, reply.type, reply.domain) do |resolved|
|
112
|
+
puts "\tdomain = #{resolved.domain}"
|
113
|
+
puts "\tflags = #{resolved.flags.inspect}"
|
114
|
+
puts "\tfullname = #{resolved.fullname}"
|
115
|
+
puts "\tinterface = #{resolved.interface}"
|
116
|
+
puts "\tname = #{resolved.name}"
|
117
|
+
puts "\tservice = #{resolved.service}"
|
118
|
+
puts "\ttarget = #{resolved.target}"
|
119
|
+
puts "\ttext_record = #{resolved.text_record.inspect}"
|
120
|
+
puts "\ttype = #{resolved.type}"
|
121
|
+
puts "\tip = #{IPSocket.getaddress(resolved.target).inspect}"
|
122
|
+
end
|
123
|
+
sleep(2)
|
124
|
+
resolver_service.stop
|
125
|
+
else
|
126
|
+
puts "removing: #{reply.inspect}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Catch the interrupt signal
|
131
|
+
interrupted = false
|
132
|
+
Signal.trap("INT") do
|
133
|
+
interrupted = true
|
134
|
+
end
|
135
|
+
|
136
|
+
# Run until the application is interrupted
|
137
|
+
loop do
|
138
|
+
if interrupted
|
139
|
+
puts "Halting network scan"
|
140
|
+
service.stop
|
141
|
+
exit
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
module FluksoLocal
|
3
|
+
|
4
|
+
class Discover
|
5
|
+
def initialize
|
6
|
+
@collection=FluksoCollection.new();
|
7
|
+
end
|
8
|
+
def getFluksoLocation
|
9
|
+
return Location.new("IP", "PORT");
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class DiscoverStaticConfiguration
|
14
|
+
def initialize(host, port)
|
15
|
+
@location=Location.new(host, port);
|
16
|
+
end
|
17
|
+
def getFluksoLocation
|
18
|
+
return @location
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Location
|
23
|
+
attr_reader :host, :port
|
24
|
+
def initialize(host, port)
|
25
|
+
@host=host
|
26
|
+
@port=port
|
27
|
+
end
|
28
|
+
def to_s
|
29
|
+
return "Flukso at #{@host}:#{@port}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class FluksoCollection
|
34
|
+
def initialize()
|
35
|
+
@locations=Array.new();
|
36
|
+
end
|
37
|
+
def locations
|
38
|
+
return @locations
|
39
|
+
end
|
40
|
+
def addLocation(location)
|
41
|
+
@location << location
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
module FluksoLocal
|
6
|
+
class Query
|
7
|
+
def initialize(location)
|
8
|
+
@location=location;
|
9
|
+
end
|
10
|
+
def getRawReadings(sensor_id)
|
11
|
+
page="/sensor/#{sensor_id}"
|
12
|
+
values=nil
|
13
|
+
begin
|
14
|
+
Net::HTTP.start(@location.host) do |http|
|
15
|
+
puts "retrieving #{page}" if $verbose
|
16
|
+
response=http.get(page);
|
17
|
+
puts "Raw Response:" if $verbose
|
18
|
+
puts response.body if $verbose
|
19
|
+
values=response.body
|
20
|
+
end
|
21
|
+
rescue StandardError => bang
|
22
|
+
puts "Cannot query flukso: #{bang}"
|
23
|
+
end
|
24
|
+
return values
|
25
|
+
end
|
26
|
+
def getReadings(sensor_id)
|
27
|
+
# todo: make appropriate nil values
|
28
|
+
retval=Hash.new
|
29
|
+
values=getRawReadings(sensor_id);
|
30
|
+
if values != nil
|
31
|
+
tmp=JSON.parse(values);
|
32
|
+
tmp.each{|value|
|
33
|
+
timestamp=value[0]
|
34
|
+
value=value[1]
|
35
|
+
#puts "Found #{timestamp} => #{value}"
|
36
|
+
retval[timestamp]=value;
|
37
|
+
}
|
38
|
+
end
|
39
|
+
jj retval if $verbose;
|
40
|
+
return retval;
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: msg-flukso-localinterface
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mathias Dalheimer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-07 00:00:00 +02:00
|
19
|
+
default_executable: msg-flukso-discover
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "The mySmartGrid project provides means to manage your household energy consumption. This gem provides the runtime environment for the Chumby: it queries the mySmartGrid webservice and forwards that information to a Flash application running on the Chumby."
|
23
|
+
email: md@gonium.net
|
24
|
+
executables:
|
25
|
+
- msg-flukso-discover
|
26
|
+
- msg-flukso-currentwatts
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files:
|
30
|
+
- README
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- bin/msg-flukso-currentwatts
|
36
|
+
- bin/msg-flukso-discover
|
37
|
+
- lib/msg-flukso-localinterface.rb
|
38
|
+
- lib/msg-flukso-localinterface/discover.rb
|
39
|
+
- lib/msg-flukso-localinterface/query.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/gonium/msg-flukso-localinterface
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.7
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Displays various information from the mySmartGrid project on your Chumby
|
74
|
+
test_files: []
|
75
|
+
|