lora-rb 0.11.0 → 0.12.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 +10 -0
- data/README.md +13 -0
- data/lib/config/config.rb +7 -4
- data/lib/core/configuration.rb +3 -1
- data/lib/lora-rb/base.rb +2 -2
- data/lib/lora-rb/mqtt/call.rb +39 -18
- data/lib/lora-rb/utility.rb +3 -3
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b03ccb7f68a985497bf5b56243bae9fb9a2fec4c
|
4
|
+
data.tar.gz: 8f28fc05ec5d849056c9820285f687720e960e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c60b0f7b8460c1d215b00be34815a58028036f4499bdd6d999cd1db7eef4a54043fc2fcd143b26aea274ab933dcbd1447a9739f008ca73a85777d5057702ec3
|
7
|
+
data.tar.gz: 061beb001e41389bb4eb0ad7149382b495b743a7d4414ec1f56e6235b561639d11ccc158d36aee48619d8b98ffdcc17c46d8b820ae2364ac39c58473803eba1d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
v0.12.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.11.0..v0.12.0) August 25th, 2017
|
2
|
+
------------------------------
|
3
|
+
* Mqtt:
|
4
|
+
* send_cmd doesn't use thread anymore. Now it subscribes each topics then read data,
|
5
|
+
ones for each downlink_response_urls
|
6
|
+
* added timeout to the configuration params
|
7
|
+
* read_data now has a timeout after which it raises a Timeout::Error. Listen, on the other hand, doesn't have it.
|
8
|
+
* read_data and listen now can use subscribed topics. To do that, set topic argument to nil
|
9
|
+
* downlink_response_urls now is an array, before it was an hash
|
10
|
+
|
1
11
|
v0.11.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.10.0..v0.11.0) August 10th, 2017
|
2
12
|
------------------------------
|
3
13
|
* Mqtt:
|
data/README.md
CHANGED
@@ -198,11 +198,24 @@ This is an example provided using mqtt protocol and the provider A2a:
|
|
198
198
|
|
199
199
|
Using MQTT, by default the param wait_response is true. This means after publishing a message it waits the response
|
200
200
|
on dedicated topic.
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
config.downlink_response_urls = [
|
204
|
+
{ name: :queued, url: 'reply/{clientid}/id/{requestid}'},
|
205
|
+
# { name: :transmitted, url: '/sub/v1/users/{username}/apps/{appid}/devices/{deveui}/events/downlink' }
|
206
|
+
# { name: :confirmed, url: nil },
|
207
|
+
]
|
208
|
+
```
|
209
|
+
|
210
|
+
For each downlink urls, a subscription is performed. Then, after the publication, a reading is made for each one.
|
211
|
+
If you expect more than one response in the same topic, add it with url=nil to not subscribe it newly
|
212
|
+
|
201
213
|
If you dont want to wait the response you just set that param to false.
|
202
214
|
|
203
215
|
```ruby
|
204
216
|
lora.send_cmd(eui: 'Insert here your device eui',
|
205
217
|
data: 'f0a1b3ff',
|
218
|
+
confirmed: false,
|
206
219
|
wait_response: false)
|
207
220
|
```
|
208
221
|
|
data/lib/config/config.rb
CHANGED
@@ -12,10 +12,13 @@ LoraRb.configure do |config|
|
|
12
12
|
config.port = 8883
|
13
13
|
config.uplink_url = '/sub/v1/users/{username}/apps/{appid}/devices/+/uplink/+'
|
14
14
|
config.downlink_url = '/api/v1/users/{username}/apps/{appid}/devices/{deveui}/downlink/post/reply/{clientid}/id/{requestid}'
|
15
|
-
config.
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
config.timeout = 10.0
|
16
|
+
# If you expect more than one response in a topic, add an item with url=nil to not subscribe it newly
|
17
|
+
config.downlink_response_urls = [
|
18
|
+
{ name: :queued, url: 'reply/{clientid}/id/{requestid}'},
|
19
|
+
# { name: :transmitted, url: '/sub/v1/users/{username}/apps/{appid}/devices/{deveui}/events/downlink' }
|
20
|
+
# { name: :confirmed, url: nil },
|
21
|
+
]
|
19
22
|
config.ssl = true
|
20
23
|
config.ssl_file = 'ssl_certificates/mqtt_ca.crt'
|
21
24
|
end
|
data/lib/core/configuration.rb
CHANGED
@@ -2,7 +2,8 @@ module LoraRb
|
|
2
2
|
class Configuration
|
3
3
|
# attr_writer :allow_sign_up
|
4
4
|
|
5
|
-
attr_accessor :protocol, :host, :port, :uplink_url, :downlink_url, :downlink_response_urls, :ssl, :ssl_file, :env
|
5
|
+
attr_accessor :protocol, :host, :port, :uplink_url, :downlink_url, :downlink_response_urls, :ssl, :ssl_file, :env,
|
6
|
+
:timeout
|
6
7
|
|
7
8
|
def initialize
|
8
9
|
@protocol = nil
|
@@ -14,6 +15,7 @@ module LoraRb
|
|
14
15
|
@ssl = nil # True if uses tls
|
15
16
|
@ssl_file = nil # The certificate's path
|
16
17
|
@env = 'development'
|
18
|
+
@timeout = 10.0
|
17
19
|
end
|
18
20
|
|
19
21
|
end
|
data/lib/lora-rb/base.rb
CHANGED
@@ -20,8 +20,8 @@ class LoraClient
|
|
20
20
|
username: LoraRb::Settings.username,
|
21
21
|
password: LoraRb::Settings.password,
|
22
22
|
ssl: LoraRb.configuration.ssl,
|
23
|
-
ssl_file: LoraRb.configuration.ssl_file
|
24
|
-
|
23
|
+
ssl_file: LoraRb.configuration.ssl_file,
|
24
|
+
timeout: LoraRb.configuration.timeout }.merge(options)
|
25
25
|
@debug = options[:debug]
|
26
26
|
@token = options[:token]
|
27
27
|
@appid = options[:appid]
|
data/lib/lora-rb/mqtt/call.rb
CHANGED
@@ -39,6 +39,7 @@ module LoraRb
|
|
39
39
|
{ debug: options[:debug] })
|
40
40
|
|
41
41
|
@downlink_url = merge_tags_to_url(options[:downlink_url])
|
42
|
+
@timeout = options[:timeout]
|
42
43
|
@wait_response = options.has_key?(:wait_response) ? options[:wait_response] : true
|
43
44
|
{'hello' => 'Lora-Rb: Ready to start!'}
|
44
45
|
end
|
@@ -71,11 +72,13 @@ module LoraRb
|
|
71
72
|
|
72
73
|
puts "#{Time.now} publish #{h_request.to_json} to #{publish_url}" if options[:debug]
|
73
74
|
|
74
|
-
|
75
75
|
responses = []
|
76
|
-
|
76
|
+
# thr_response = nil
|
77
77
|
if options[:wait_response]
|
78
|
-
@downlink_response_urls.each do |
|
78
|
+
@downlink_response_urls.each do |dru_hash|
|
79
|
+
name, response_url = dru_hash[:name], dru_hash[:url]
|
80
|
+
next unless response_url
|
81
|
+
|
79
82
|
# response_topic = "reply/#{@client_id}/id/#{request_id}"
|
80
83
|
response_topic = merge_tags_to_url(response_url,
|
81
84
|
username: @username,
|
@@ -83,13 +86,8 @@ module LoraRb
|
|
83
86
|
deveui: options[:eui],
|
84
87
|
clientid: @client_id,
|
85
88
|
requestid: request_id)
|
86
|
-
puts " [x]
|
87
|
-
|
88
|
-
response_topic, response_message = sub_read_data(topic: response_topic)
|
89
|
-
response = { name: name, topic: response_topic, json: response_message }
|
90
|
-
puts " [x] End thread with response #{response} " if options[:debug] == :full
|
91
|
-
responses << response
|
92
|
-
end
|
89
|
+
puts " [x] Subscribing response #{response_topic}" if options[:debug] == :full
|
90
|
+
@client.subscribe(response_topic)
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
@@ -97,31 +95,54 @@ module LoraRb
|
|
97
95
|
|
98
96
|
if options[:wait_response]
|
99
97
|
# Waiting for all the responses
|
100
|
-
thr_responses.each { |thr_response| thr_response.join }
|
98
|
+
# thr_responses.each { |thr_response| thr_response.join }
|
99
|
+
# thr_response.join
|
100
|
+
@downlink_response_urls.each do |dru_hash|
|
101
|
+
response_topic, response_message = sub_read_data(topic: nil)
|
102
|
+
response = { topic: response_topic, json: response_message }
|
103
|
+
puts " [x] Found response #{response} " if options[:debug] == :full
|
104
|
+
responses << response
|
105
|
+
end
|
101
106
|
end
|
102
107
|
responses
|
103
108
|
end
|
104
109
|
|
105
110
|
# Receive the payload from the network
|
111
|
+
# There is a timeout. Use this method only to retrieve data from the queue. If you have to waiting data
|
112
|
+
# please use listen.
|
106
113
|
def sub_read_data(options={})
|
107
|
-
topic = options[:topic]
|
108
|
-
|
109
|
-
|
114
|
+
topic = options.has_key?(:topic) ? options[:topic] : @topic
|
115
|
+
if topic
|
116
|
+
topic = topic.dup
|
117
|
+
puts " [x] Reading topic #{topic}..." if options[:debug]
|
118
|
+
end
|
119
|
+
|
120
|
+
message = nil
|
121
|
+
begin
|
122
|
+
Timeout.timeout(options[:timeout] || @timeout) do
|
123
|
+
topic, message = @client.get(topic)
|
124
|
+
end
|
125
|
+
rescue Timeout::Error
|
126
|
+
message = {error: 'Timeout'}.to_json
|
127
|
+
end
|
128
|
+
|
110
129
|
message = JSON.parse(message)
|
111
130
|
if message.respond_to? '[]'
|
112
131
|
message['eui'] ||= get_eui_from_topic(topic)
|
113
132
|
message['port'] ||= get_port_from_topic(topic)
|
114
133
|
end
|
115
|
-
puts " [x] #{topic}: #{message}" if options[:debug]
|
116
134
|
return topic, message
|
117
135
|
end
|
118
136
|
|
119
137
|
# Waiting for message in the queue
|
120
138
|
def sub_listen(options={}, &block)
|
121
|
-
topic = options[:topic]
|
122
|
-
|
139
|
+
topic = options.has_key?(:topic) ? options[:topic] : @topic
|
140
|
+
if topic
|
141
|
+
topic = topic.dup
|
142
|
+
puts " [*] Waiting for messages in #{topic}. To exit press CTRL+C" if options[:debug]
|
143
|
+
end
|
123
144
|
|
124
|
-
@client.get(topic
|
145
|
+
@client.get(topic) do |topic, message|
|
125
146
|
# Block is executed for every message received
|
126
147
|
puts " [x] #{topic}: #{message}" if options[:debug]
|
127
148
|
message = JSON.parse(message)
|
data/lib/lora-rb/utility.rb
CHANGED
@@ -7,12 +7,12 @@ module LoraRb
|
|
7
7
|
# Show tips on usage
|
8
8
|
def merge_tags_to_url(url, tags={}, options={})
|
9
9
|
url = url.dup
|
10
|
-
puts "merge_tags_to_url: #{url}" if options[:debug]
|
10
|
+
puts "merge_tags_to_url: #{url}" if options[:debug] == :full
|
11
11
|
tags.each do |tag, value|
|
12
|
-
puts " replace {#{tag}} with #{value}" if options[:debug]
|
12
|
+
puts " replace {#{tag}} with #{value}" if options[:debug] == :full
|
13
13
|
url.gsub!("{#{tag}}", value.to_s)
|
14
14
|
end
|
15
|
-
puts "merge_tags_to_url: completed #{url}" if options[:debug]
|
15
|
+
puts "merge_tags_to_url: completed #{url}" if options[:debug] == :full
|
16
16
|
url
|
17
17
|
end
|
18
18
|
end
|
data/lib/version.rb
CHANGED