saal 0.3.4 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/saal_envoy_generate_config +15 -31
- data/bin/saal_envoy_read +7 -10
- data/lib/envoy.rb +10 -7
- data/lib/http.rb +9 -14
- data/lib/saal.rb +1 -1
- data/saal.gemspec +3 -3
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a73d98e715e7b0460b414451f12d729f6c7ba0073a8c9f07fb1312cbf8e3088c
|
4
|
+
data.tar.gz: 5862c4608df8505117888d230f7318cf67b7d1674f9119354bb3cc0c6b9205f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9691af2407d177050886eb9754d164cea5b76044e14b42db23b176fc5efd1ce84bbc9986582a075c9ed9cd4e2648cc9d9c76c3c9c6543aaa5a5c1dd18a76d6a
|
7
|
+
data.tar.gz: 7f55fb52f23eb87744fe592a879295326d06b61ee046ae39fed2ae093d11c280f2988fb20fa4a0e6e67c48a7314eb93e5f1f2dca0ddc6133108a0f5a350cff32
|
@@ -2,51 +2,35 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__)+'/../lib/saal.rb'
|
4
4
|
|
5
|
-
if ARGV.size !=
|
6
|
-
$stderr.puts "USAGE: saal_envoy_generate_config <host>
|
5
|
+
if ARGV.size != 2
|
6
|
+
$stderr.puts "USAGE: saal_envoy_generate_config <host> <token>"
|
7
7
|
exit(1)
|
8
8
|
end
|
9
9
|
|
10
|
+
envoy = SAAL::Envoy::Inverters::new(
|
11
|
+
:host => ARGV[0],
|
12
|
+
:token => ARGV[1],
|
13
|
+
)
|
14
|
+
envoy.set_all_inverters!
|
15
|
+
if envoy.inverters.size <= 0
|
16
|
+
$stderr.puts "ERROR: Couldn't find any inverters!"
|
17
|
+
exit 0
|
18
|
+
end
|
19
|
+
|
10
20
|
puts "power:"
|
11
21
|
puts " envoy_power_energy:"
|
12
22
|
puts " host: \"#{ARGV[0]}\""
|
23
|
+
puts " token: \"#{ARGV[1]}\""
|
13
24
|
puts
|
14
25
|
puts "ac:"
|
15
26
|
puts " envoy_ac_quality:"
|
16
27
|
puts " host: \"#{ARGV[0]}\""
|
17
|
-
|
18
|
-
user = "envoy"
|
19
|
-
password = nil
|
20
|
-
|
21
|
-
if ARGV[2]
|
22
|
-
user = ARGV[1]
|
23
|
-
password = ARGV[2]
|
24
|
-
else
|
25
|
-
Net::HTTP.get(ARGV[0], '/home').split("\n").each do |line|
|
26
|
-
if line.include?("serial:")
|
27
|
-
password = line.split('"')[1][-6..-1]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
if !password
|
31
|
-
$stderr.puts "Couldn't find serial number for envoy"
|
32
|
-
exit 2
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
envoy = SAAL::Envoy::Inverters::new(
|
37
|
-
:host => ARGV[0],
|
38
|
-
:user => user,
|
39
|
-
:password => password,
|
40
|
-
)
|
41
|
-
envoy.set_all_inverters!
|
42
|
-
exit 0 if envoy.inverters.size <= 0
|
43
|
-
|
28
|
+
puts " token: \"#{ARGV[1]}\""
|
44
29
|
puts
|
45
30
|
puts "inverters:"
|
46
31
|
puts " envoy_inverters:"
|
47
32
|
puts " host: \"#{ARGV[0]}\""
|
48
|
-
puts "
|
49
|
-
puts " password: \"#{password}\""
|
33
|
+
puts " token: \"#{ARGV[1]}\""
|
50
34
|
puts " inverters:"
|
51
35
|
envoy.inverters.each do |serial|
|
52
36
|
puts " - #{serial}"
|
data/bin/saal_envoy_read
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__)+'/../lib/saal.rb'
|
4
4
|
|
5
|
-
if ARGV.size !=
|
6
|
-
$stderr.puts "USAGE: saal_envoy_read <host> <
|
5
|
+
if ARGV.size != 2
|
6
|
+
$stderr.puts "USAGE: saal_envoy_read <host> <token>"
|
7
7
|
exit(1)
|
8
8
|
end
|
9
9
|
|
10
|
+
config = {:host => ARGV[0], :token => ARGV[1]}
|
11
|
+
|
10
12
|
def fdisp(val)
|
11
13
|
if val
|
12
14
|
'%10.0f' % val
|
@@ -58,7 +60,7 @@ def lratio(vals, name1, name2)
|
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
ac_quality = SAAL::Envoy::ACQuality::new(
|
63
|
+
ac_quality = SAAL::Envoy::ACQuality::new(config).create_sensors
|
62
64
|
|
63
65
|
puts " ========= AC QUALITY ========"
|
64
66
|
puts " voltage (V) freq (Hz)"
|
@@ -73,7 +75,7 @@ qual_line(ac_quality, "Phase1:", "phase1")
|
|
73
75
|
qual_line(ac_quality, "Phase2:", "phase2")
|
74
76
|
qual_line(ac_quality, "Phase3:", "phase3")
|
75
77
|
|
76
|
-
production = SAAL::Envoy::PowerEnergy::new(
|
78
|
+
production = SAAL::Envoy::PowerEnergy::new(config).create_sensors
|
77
79
|
|
78
80
|
puts ""
|
79
81
|
puts " ============ TRUE POWER (W) ============ ======= TRUE ENERGY (kWh) ======="
|
@@ -134,12 +136,7 @@ pf_line(production, "Phase2:", "phase2", "va")
|
|
134
136
|
pf_line(production, "Phase3:", "phase3", "va")
|
135
137
|
|
136
138
|
puts ""
|
137
|
-
envoy = SAAL::Envoy::Inverters::new(
|
138
|
-
:host => ARGV[0],
|
139
|
-
:user => ARGV[1],
|
140
|
-
:password => ARGV[2],
|
141
|
-
:types => ["w_now", "last_report_date", "w_max"],
|
142
|
-
)
|
139
|
+
envoy = SAAL::Envoy::Inverters::new(config.merge({:types => ["w_now", "last_report_date", "w_max"]}))
|
143
140
|
envoy.set_all_inverters!
|
144
141
|
inverters = envoy.create_sensors
|
145
142
|
puts " Found #{envoy.inverters.size} inverters"
|
data/lib/envoy.rb
CHANGED
@@ -15,6 +15,7 @@ module SAAL
|
|
15
15
|
|
16
16
|
class PowerEnergy
|
17
17
|
DEFAULT_HOST = "envoy.local"
|
18
|
+
DEFAULT_TOKEN = ""
|
18
19
|
DEFAULT_TIMEOUT = 2
|
19
20
|
DEFAULT_CACHE_TIMEOUT = 5
|
20
21
|
DEFAULT_SOURCES = [
|
@@ -30,6 +31,7 @@ module SAAL
|
|
30
31
|
|
31
32
|
def initialize(defs, opts={})
|
32
33
|
@host = defs[:host] || defs['host'] || DEFAULT_HOST
|
34
|
+
@token = defs[:token] || defs['token'] || DEFAULT_TOKEN
|
33
35
|
@timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT
|
34
36
|
@cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT
|
35
37
|
@cache = nil
|
@@ -85,7 +87,7 @@ module SAAL
|
|
85
87
|
end
|
86
88
|
|
87
89
|
def read_all
|
88
|
-
response = SAAL::
|
90
|
+
response = SAAL::do_https_get_token(@host, "/production.json?details=1", @token, @timeout)
|
89
91
|
return nil if !response
|
90
92
|
|
91
93
|
values = JSON.parse(response.body)
|
@@ -139,6 +141,7 @@ module SAAL
|
|
139
141
|
|
140
142
|
class ACQuality
|
141
143
|
DEFAULT_HOST = "envoy.local"
|
144
|
+
DEFAULT_TOKEN = ""
|
142
145
|
DEFAULT_TIMEOUT = 2
|
143
146
|
DEFAULT_CACHE_TIMEOUT = 5
|
144
147
|
DEFAULT_SOURCES = ["total","phase1","phase2","phase3",]
|
@@ -147,6 +150,7 @@ module SAAL
|
|
147
150
|
|
148
151
|
def initialize(defs, opts={})
|
149
152
|
@host = defs[:host] || defs['host'] || DEFAULT_HOST
|
153
|
+
@token = defs[:token] || defs['token'] || DEFAULT_TOKEN
|
150
154
|
@timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT
|
151
155
|
@cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT
|
152
156
|
@cache = nil
|
@@ -184,7 +188,7 @@ module SAAL
|
|
184
188
|
end
|
185
189
|
|
186
190
|
def read_all
|
187
|
-
response = SAAL::
|
191
|
+
response = SAAL::do_https_get_token(@host, "/ivp/meters/readings", @token, @timeout)
|
188
192
|
return nil if !response
|
189
193
|
|
190
194
|
values = JSON.parse(response.body)
|
@@ -213,19 +217,18 @@ module SAAL
|
|
213
217
|
end
|
214
218
|
|
215
219
|
class Inverters
|
220
|
+
DEFAULT_HOST = "envoy.local"
|
221
|
+
DEFAULT_TOKEN = nil
|
216
222
|
DEFAULT_TIMEOUT = 2
|
217
223
|
DEFAULT_CACHE_TIMEOUT = 50
|
218
224
|
DEFAULT_SOURCES = []
|
219
225
|
DEFAULT_TYPES = ["w_now"] # "last_report_date", "w_max"
|
220
|
-
DEFAULT_USER = nil
|
221
|
-
DEFAULT_PASSWORD = nil
|
222
226
|
DEFAULT_PREFIX = "inverters"
|
223
227
|
attr_reader :inverters
|
224
228
|
|
225
229
|
def initialize(defs, opts={})
|
226
230
|
@host = defs[:host] || defs['host'] || DEFAULT_HOST
|
227
|
-
@
|
228
|
-
@password = defs[:password] || defs['password'] || DEFAULT_PASSWORD
|
231
|
+
@token = defs[:token] || defs['token'] || DEFAULT_TOKEN
|
229
232
|
@timeout = opts[:timeout] || opts['timeout'] || DEFAULT_TIMEOUT
|
230
233
|
@cache_timeout = opts[:cache_timeout] || opts['cache_timeout'] || DEFAULT_CACHE_TIMEOUT
|
231
234
|
@cache = nil
|
@@ -264,7 +267,7 @@ module SAAL
|
|
264
267
|
|
265
268
|
private
|
266
269
|
def read_all
|
267
|
-
response = SAAL::
|
270
|
+
response = SAAL::do_https_get_token(@host, "/api/v1/production/inverters", @token, @timeout)
|
268
271
|
return nil if !response
|
269
272
|
|
270
273
|
values = JSON.parse(response.body)
|
data/lib/http.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'net/http'
|
3
|
-
require '
|
3
|
+
require 'openssl'
|
4
4
|
|
5
5
|
def SAAL::do_http_get(host, port, path, user, pass, timeout)
|
6
6
|
begin
|
@@ -22,26 +22,21 @@ def SAAL::do_http_get(host, port, path, user, pass, timeout)
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def SAAL::
|
25
|
+
def SAAL::do_https_get_token(host, path, token, timeout)
|
26
26
|
begin
|
27
|
-
|
28
|
-
digest_auth = Net::HTTP::DigestAuth.new
|
29
|
-
uri.user = user
|
30
|
-
uri.password = pass
|
31
|
-
http = Net::HTTP.new(host,port)
|
27
|
+
http = Net::HTTP.new(host,443)
|
32
28
|
# Timeout faster when the other side doesn't respond
|
33
29
|
http.open_timeout = timeout
|
34
30
|
http.read_timeout = timeout
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
33
|
req = Net::HTTP::Get.new(path)
|
34
|
+
req['Accept'] = "application/json"
|
35
|
+
req['Authorization'] = "Bearer #{token}"
|
36
36
|
response = http.request(req)
|
37
|
-
if response.code == "401" && user && pass
|
38
|
-
auth = digest_auth.auth_header uri, response['www-authenticate'], 'GET'
|
39
|
-
req.add_field 'Authorization', auth
|
40
|
-
response = http.request(req)
|
41
|
-
end
|
42
37
|
if response.code != "200"
|
43
|
-
|
44
|
-
|
38
|
+
$stderr.puts "ERROR: Code #{response.code}"
|
39
|
+
$stderr.puts response.body
|
45
40
|
return nil
|
46
41
|
end
|
47
42
|
return response
|
data/lib/saal.rb
CHANGED
data/saal.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
|
8
8
|
s.name = 'saal'
|
9
|
-
s.version = '0.3.
|
10
|
-
s.date = '
|
9
|
+
s.version = '0.3.6'
|
10
|
+
s.date = '2024-02-08'
|
11
11
|
|
12
12
|
s.summary = "Thin abstraction layer for interfacing and recording sensors (currently onewire) and actuators (currently dinrelay)"
|
13
13
|
s.description = <<EOF
|
@@ -32,7 +32,7 @@ EOF
|
|
32
32
|
s.add_runtime_dependency 'ownet', "~>0.2"
|
33
33
|
s.add_runtime_dependency 'mysql2', "~>0.5"
|
34
34
|
s.add_runtime_dependency 'nokogiri', '~>1.8'
|
35
|
-
s.add_runtime_dependency '
|
35
|
+
s.add_runtime_dependency 'openssl', '~>2'
|
36
36
|
|
37
37
|
# = MANIFEST =
|
38
38
|
s.files = %w[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Côrte-Real
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ownet
|
@@ -53,34 +53,34 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: openssl
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2'
|
69
69
|
description: "A daemon and libraries to create an abstraction layer that interfaces
|
70
70
|
with \nsensors and actuators, recording their state, responding to requests \nfor
|
71
71
|
current and historical values, and allowing changes of state.\n"
|
72
72
|
email: pedro@pedrocr.net
|
73
73
|
executables:
|
74
|
-
- dinrelaystatus
|
75
74
|
- dinrelayset
|
76
|
-
-
|
77
|
-
- saal_dump_database
|
78
|
-
- saal_readall
|
79
|
-
- saal_denkovi_relays
|
75
|
+
- dinrelaystatus
|
80
76
|
- saal_chart
|
81
77
|
- saal_daemon
|
78
|
+
- saal_denkovi_relays
|
79
|
+
- saal_dump_database
|
82
80
|
- saal_envoy_generate_config
|
83
81
|
- saal_envoy_read
|
82
|
+
- saal_import_mysql
|
83
|
+
- saal_readall
|
84
84
|
extensions: []
|
85
85
|
extra_rdoc_files:
|
86
86
|
- README.rdoc
|
@@ -140,7 +140,7 @@ homepage: https://github.com/pedrocr/saal
|
|
140
140
|
licenses:
|
141
141
|
- LGPL-2.1
|
142
142
|
metadata: {}
|
143
|
-
post_install_message:
|
143
|
+
post_install_message:
|
144
144
|
rdoc_options:
|
145
145
|
- "-S"
|
146
146
|
- "-w 2"
|
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
162
|
+
rubygems_version: 3.3.5
|
163
|
+
signing_key:
|
164
164
|
specification_version: 2
|
165
165
|
summary: Thin abstraction layer for interfacing and recording sensors (currently onewire)
|
166
166
|
and actuators (currently dinrelay)
|