lora-rb 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/config/config.rb +4 -2
- data/lib/core/base.rb +10 -0
- data/lib/core/protocol.rb +11 -0
- data/lib/lora-rb.rb +2 -9
- data/lib/lora-rb/base.rb +2 -8
- data/lib/lora-rb/http/call.rb +6 -0
- data/lib/lora-rb/mqtt/call.rb +61 -0
- data/lib/lora-rb/tls/call.rb +11 -0
- data/lib/version.rb +1 -1
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a328956e282ef7fc3fc65942183c4373d304850c
|
4
|
+
data.tar.gz: '049b381a5922987c282f21f39562416c76265ccb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ee3a2d4016d80b24b44b05f128c2c37791c712e9c925900615ef460aa2d753f474f7c952d68aa1a3e63bab4ce7dec1b0191abf8442a761943bf98687b78f02
|
7
|
+
data.tar.gz: dff6d02731671b3074e915f5ff224686c28ccd9b857286b56f2cbb4e6ffc12dd42df33765ed9ec49326488e511bff6a06e8e701ca3fe3cdd45817c7992e2982d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.6.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.5.0..v0.6.0) June 28th, 2017
|
2
|
+
------------------------------
|
3
|
+
* Now support mqtt to get and receive data throught RabbitMQ
|
4
|
+
* Code cleaning
|
5
|
+
|
1
6
|
v0.5.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.4.0..v0.5.0) June 27th, 2017
|
2
7
|
------------------------------
|
3
8
|
* Now support http push to send data with an internal http client (only send data, to receive you must have an http server)
|
data/lib/config/config.rb
CHANGED
@@ -3,7 +3,9 @@ LoraRb.configure do |config|
|
|
3
3
|
# config.protocol = :tls
|
4
4
|
# config.host = 'eu1.loriot.io'
|
5
5
|
# config.port = 737
|
6
|
-
config.protocol = :http
|
7
|
-
config.
|
6
|
+
# config.protocol = :http
|
7
|
+
config.protocol = :mqtt
|
8
|
+
# config.host = 'eu72.resiot.io'
|
9
|
+
config.host = 'localhost'
|
8
10
|
config.port = 80
|
9
11
|
end
|
data/lib/core/base.rb
ADDED
data/lib/lora-rb.rb
CHANGED
@@ -13,13 +13,7 @@
|
|
13
13
|
# You should have received a copy of the GNU General Public License
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
-
|
17
|
-
require 'socket'
|
18
|
-
require 'openssl'
|
19
|
-
require 'http'
|
20
|
-
|
21
|
-
require_relative 'core/configuration'
|
22
|
-
require_relative 'core/configuration_dynamic'
|
16
|
+
require_relative 'core/base'
|
23
17
|
|
24
18
|
module LoraRb
|
25
19
|
def self.root
|
@@ -27,7 +21,6 @@ module LoraRb
|
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
|
-
require_relative 'version'
|
31
24
|
require_relative 'lora-rb/base'
|
32
25
|
|
33
26
|
unless defined?(Rails)
|
@@ -35,7 +28,7 @@ unless defined?(Rails)
|
|
35
28
|
|
36
29
|
connection_protocol = LoraRb.configuration.protocol
|
37
30
|
raise "Define your protocol in the configuration file!" unless connection_protocol
|
38
|
-
raise "Connection protocol #{connection_protocol} not recognized!" unless
|
31
|
+
raise "Connection protocol #{connection_protocol} not recognized!" unless LoraRb::Protocol.supported_protocols.include?(connection_protocol.to_s)
|
39
32
|
require_relative "lora-rb/#{connection_protocol}/call"
|
40
33
|
LoraClient.include LoraRb::Call
|
41
34
|
|
data/lib/lora-rb/base.rb
CHANGED
@@ -54,14 +54,8 @@ class LoraClient
|
|
54
54
|
def listen(options = {}, &block)
|
55
55
|
options = { debug: @debug }.merge(options)
|
56
56
|
|
57
|
-
puts "#{Time.now} Starting Listen #{@appid}" if options[:debug]
|
58
|
-
|
59
|
-
begin
|
60
|
-
response = read_data(options)
|
61
|
-
block.call(response) if block
|
62
|
-
end while response && !options[:test]
|
63
|
-
# Return last response
|
64
|
-
response
|
57
|
+
puts "#{Time.now} Starting Listen #{@appid}. To exit press CTRL+C" if options[:debug]
|
58
|
+
sub_listen(options)
|
65
59
|
end
|
66
60
|
|
67
61
|
# Close the secure connection with the cloud
|
data/lib/lora-rb/http/call.rb
CHANGED
@@ -37,6 +37,12 @@ module LoraRb
|
|
37
37
|
raise('In http protocol, it expects data with an http server. Lora Network server must exec an http push ')
|
38
38
|
end
|
39
39
|
|
40
|
+
# Waiting for messages
|
41
|
+
def sub_listen(options={})
|
42
|
+
raise('In http protocol, it expects data with an http server. Lora Network server must exec an http push ')
|
43
|
+
end
|
44
|
+
|
45
|
+
# Blank method. No need to close a connection with the http protocol
|
40
46
|
def sub_quit
|
41
47
|
end
|
42
48
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# LoraRb calling methods
|
2
|
+
module LoraRb
|
3
|
+
# It contains all the methods for selecting the items
|
4
|
+
module Call
|
5
|
+
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def sub_initialize(options={})
|
11
|
+
@connection = Bunny.new(hostname: options[:host])
|
12
|
+
@connection.start
|
13
|
+
@channel = @connection.create_channel
|
14
|
+
@queue = @channel.queue(options[:queue])
|
15
|
+
{'hello' => 'Lora-Rb: Ready to start!'}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Send the request to device
|
19
|
+
def sub_send_cmd(options={})
|
20
|
+
str_request = "{\"cmd\":\"#{options[:cmd]}\",\"EUI\":\"#{options[:eui]}\",\"port\":#{options[:port]},\"confirmed\":#{options[:confirmed]},\"data\":\"#{options[:data]}\"} "
|
21
|
+
puts "#{Time.now} Cmq request: #{str_request}" if options[:debug]
|
22
|
+
response = @channel.default_exchange.publish(str_request, routing_key: @queue.name)
|
23
|
+
puts " [x] Sent '#{str_request}'" if options[:debug]
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
# Receive the payload from the network
|
28
|
+
def sub_read_data(options={})
|
29
|
+
delivery_info, metadata, payload = @queue.pop
|
30
|
+
puts " [x] Received #{delivery_info} #{metadata} #{payload}" if options[:debug]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Waiting for message in the queue
|
34
|
+
def sub_listen(options={}, &block)
|
35
|
+
puts " [*] Waiting for messages in #{@queue.name}. To exit press CTRL+C" if options[:debug]
|
36
|
+
@queue.subscribe(block: true) do |delivery_info, properties, body|
|
37
|
+
puts " [x] Received #{body}" if options[:debug]
|
38
|
+
block.call(delivery_info, properties, body) if block
|
39
|
+
# cancel the consumer to exit
|
40
|
+
delivery_info.consumer.cancel
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Close the connection
|
45
|
+
def sub_quit
|
46
|
+
@connection.close
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Monkey patch since Bunny use the rails method .empty?
|
53
|
+
class NilClass
|
54
|
+
def empty?; true end
|
55
|
+
end
|
56
|
+
# Example
|
57
|
+
=begin
|
58
|
+
require 'lora-rb'
|
59
|
+
lora=LoraClient.new
|
60
|
+
lora.send_cmd(eui: 'BE7A00000000123C')
|
61
|
+
=end
|
data/lib/lora-rb/tls/call.rb
CHANGED
@@ -65,6 +65,17 @@ module LoraRb
|
|
65
65
|
JSON.parse(response)
|
66
66
|
end
|
67
67
|
|
68
|
+
# Waiting for message
|
69
|
+
def sub_listen(options={}, &block)
|
70
|
+
response = nil
|
71
|
+
begin
|
72
|
+
response = sub_read_data(options)
|
73
|
+
puts " [x] Received #{response}" if options[:debug]
|
74
|
+
block.call(response) if block
|
75
|
+
end while response && !options[:test]
|
76
|
+
end
|
77
|
+
|
78
|
+
# Close the connection
|
68
79
|
def sub_quit
|
69
80
|
@ssl_socket.close
|
70
81
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lora-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Mastrodonato
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '2.
|
21
|
+
version: '2.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '2.
|
28
|
+
version: '2.1'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: openssl
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,14 +46,28 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '2.
|
49
|
+
version: '2.2'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '2.
|
56
|
+
version: '2.2'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: bunny
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.7'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.7'
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: test-unit
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,13 +98,16 @@ files:
|
|
84
98
|
- lib/config/config.rb
|
85
99
|
- lib/config/private.yml
|
86
100
|
- lib/config/private_EXAMPLE.yml
|
101
|
+
- lib/core/base.rb
|
87
102
|
- lib/core/configuration.rb
|
88
103
|
- lib/core/configuration_dynamic.rb
|
104
|
+
- lib/core/protocol.rb
|
89
105
|
- lib/generators/install_generator.rb
|
90
106
|
- lib/lora-rb.rb
|
91
107
|
- lib/lora-rb/base.rb
|
92
108
|
- lib/lora-rb/help.rb
|
93
109
|
- lib/lora-rb/http/call.rb
|
110
|
+
- lib/lora-rb/mqtt/call.rb
|
94
111
|
- lib/lora-rb/tls/call.rb
|
95
112
|
- lib/vendor/deep_symbolize.rb
|
96
113
|
- lib/version.rb
|