Floppy-currentcost 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +19 -0
- data/README +30 -0
- data/lib/currentcost.rb +6 -0
- data/lib/currentcost/exceptions.rb +6 -0
- data/lib/currentcost/meter.rb +15 -0
- data/lib/currentcost/reading.rb +64 -0
- data/lib/currentcost/version.rb +10 -0
- metadata +59 -0
data/COPYING
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 James Smith (james@floppy.org.uk)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
== CurrentCost-Ruby
|
2
|
+
|
3
|
+
A gem to provide a Ruby interface to the CurrentCost energy meter
|
4
|
+
(http://www.currentcost.com)
|
5
|
+
|
6
|
+
Licensed under the MIT license (See COPYING file for details)
|
7
|
+
|
8
|
+
Author: James Smith (james@floppy.org.uk / http://www.floppy.org.uk)
|
9
|
+
|
10
|
+
Homepage: http://github.com/Floppy/currentcost-ruby
|
11
|
+
|
12
|
+
== INSTALLATION
|
13
|
+
|
14
|
+
1) Enable gems from github, if you haven't already done so (rubygems >= 1.2):
|
15
|
+
> sudo gem sources -a http://gems.github.com
|
16
|
+
|
17
|
+
2) Install gem
|
18
|
+
> sudo gem install Floppy-currentcost
|
19
|
+
|
20
|
+
== REQUIREMENTS
|
21
|
+
|
22
|
+
ruby-serialport >= 0.7.0
|
23
|
+
- You will need to get the source from http://github.com/aaronp/ruby-serialport,
|
24
|
+
build the gem using "rake gem", and install it before using this gem.
|
25
|
+
|
26
|
+
== STATUS
|
27
|
+
|
28
|
+
This software is in very early development. There is currently no direct access
|
29
|
+
to the meter via serial port, but you can use CurrentCost::Reading.from_xml to
|
30
|
+
parse XML which you have got from the meter another way.
|
data/lib/currentcost.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module CurrentCost
|
2
|
+
|
3
|
+
class Reading
|
4
|
+
|
5
|
+
def self.from_xml(xml)
|
6
|
+
# Parse XML
|
7
|
+
doc = REXML::Document.new(xml)
|
8
|
+
# Create reading object
|
9
|
+
r = Reading.new
|
10
|
+
# Extract basic data
|
11
|
+
r.days_since_birth = REXML::XPath.first(doc, "/msg/date/dsb").text.to_i
|
12
|
+
r.hour = REXML::XPath.first(doc, "/msg/date/hr").text.to_i
|
13
|
+
r.minute = REXML::XPath.first(doc, "/msg/date/min").text.to_i
|
14
|
+
r.second = REXML::XPath.first(doc, "/msg/date/sec").text.to_i
|
15
|
+
r.name = REXML::XPath.first(doc, "/msg/src/name").text
|
16
|
+
r.id = REXML::XPath.first(doc, "/msg/src/id").text
|
17
|
+
r.type = REXML::XPath.first(doc, "/msg/src/type").text
|
18
|
+
r.software_version = REXML::XPath.first(doc, "/msg/src/sver").text
|
19
|
+
r.temperature = REXML::XPath.first(doc, "/msg/tmpr").text.to_f
|
20
|
+
r.channels = []
|
21
|
+
REXML::XPath.each(doc, "/msg/*/watts") do |node|
|
22
|
+
r.channels << { :watts => node.text.to_i }
|
23
|
+
end
|
24
|
+
# Extract history data
|
25
|
+
if REXML::XPath.first(doc, "/msg/hist")
|
26
|
+
r.history = {}
|
27
|
+
r.history[:hours] = []
|
28
|
+
REXML::XPath.each(doc, "/msg/hist/hrs/*") do |node|
|
29
|
+
r.history[:hours][node.name.slice(1,2).to_i] = node.text.to_f
|
30
|
+
end
|
31
|
+
r.history[:days] = []
|
32
|
+
REXML::XPath.each(doc, "/msg/hist/days/*") do |node|
|
33
|
+
r.history[:days][node.name.slice(1,2).to_i] = node.text.to_i
|
34
|
+
end
|
35
|
+
r.history[:months] = []
|
36
|
+
REXML::XPath.each(doc, "/msg/hist/mths/*") do |node|
|
37
|
+
r.history[:months][node.name.slice(1,2).to_i] = node.text.to_i
|
38
|
+
end
|
39
|
+
r.history[:years] = []
|
40
|
+
REXML::XPath.each(doc, "/msg/hist/yrs/*") do |node|
|
41
|
+
r.history[:years][node.name.slice(1,2).to_i] = node.text.to_i
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# Done
|
45
|
+
return r
|
46
|
+
rescue
|
47
|
+
raise CurrentCost::ParseError.new("Couldn't parse XML data.")
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_accessor :days_since_birth
|
51
|
+
attr_accessor :hour
|
52
|
+
attr_accessor :minute
|
53
|
+
attr_accessor :second
|
54
|
+
attr_accessor :name
|
55
|
+
attr_accessor :id
|
56
|
+
attr_accessor :type
|
57
|
+
attr_accessor :software_version
|
58
|
+
attr_accessor :channels
|
59
|
+
attr_accessor :temperature
|
60
|
+
attr_accessor :history
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Floppy-currentcost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: james@floppy.org.uk
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- COPYING
|
27
|
+
- lib/currentcost.rb
|
28
|
+
- lib/currentcost/meter.rb
|
29
|
+
- lib/currentcost/reading.rb
|
30
|
+
- lib/currentcost/version.rb
|
31
|
+
- lib/currentcost/exceptions.rb
|
32
|
+
has_rdoc: false
|
33
|
+
homepage: http://github.com/Floppy/currentcost-ruby
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Ruby interface to the CurrentCost energy meter
|
58
|
+
test_files: []
|
59
|
+
|