lora-rb 0.10.0 → 0.11.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 +6 -0
- data/README.md +12 -3
- data/lib/config/config.rb +4 -0
- data/lib/core/configuration.rb +4 -2
- data/lib/lora-rb/base.rb +3 -0
- data/lib/lora-rb/mqtt/call.rb +34 -21
- 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: fa20e294270b6a37671b7d98b8afe2d70f19ea1f
|
4
|
+
data.tar.gz: 5510af9e4a7d1a0ffe716531ae595a4680812905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76a047649347b811eb85fa7e8f1728208b1c404c318fc75360421dab2011e245a4b4ffd51344ffb237daac85ff8e1eb08999e3769865a3406b2e1a2532ff39d3
|
7
|
+
data.tar.gz: d7400a832dabe4cb4d2bc69917048be49d12406886e36fd55ad90136efc0d38cac7bb75d019bce2fe5c4408d245bbab0b0505058f8cfbb7d984b6c91b58f86b4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v0.11.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.10.0..v0.11.0) August 10th, 2017
|
2
|
+
------------------------------
|
3
|
+
* Mqtt:
|
4
|
+
* now you can manage response from the configuration and define multiple response topics: queued, transmitted...
|
5
|
+
* send cmd message now contains multiple informations
|
6
|
+
|
1
7
|
v0.10.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.9.0..v0.10.0) August 8th, 2017
|
2
8
|
------------------------------
|
3
9
|
* Mqtt:
|
data/README.md
CHANGED
@@ -25,9 +25,10 @@ To use this gem you have to choose your provider. Each of them has its own featu
|
|
25
25
|
among which you can choose to connect to the lora network.
|
26
26
|
|
27
27
|
This version supports:
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
|
29
|
+
1. TLS protocol with [Loriot](http://loriot.io)
|
30
|
+
2. Http push with [Resiot](http://resiot.io)
|
31
|
+
3. MQTT with [A2aSmartCity](http://www.a2asmartcity.io/)
|
31
32
|
|
32
33
|
## Configuration
|
33
34
|
|
@@ -103,6 +104,10 @@ end
|
|
103
104
|
|
104
105
|
### MQTT (with A2a)
|
105
106
|
|
107
|
+
Insert in uplink_url the topic url where to wait the device messages.
|
108
|
+
Insert in downlink_url the topic url where publish the message to send to the device.
|
109
|
+
Insert in downlink_response_urls the list of topic urls where the lora network put the response. Use a label as phase's name.
|
110
|
+
|
106
111
|
```ruby
|
107
112
|
LoraRb.configure do |config|
|
108
113
|
config.protocol = :mqtt
|
@@ -110,6 +115,10 @@ LoraRb.configure do |config|
|
|
110
115
|
config.port = 8883
|
111
116
|
config.uplink_url = '/sub/v1/users/{username}/apps/{appid}/devices/+/uplink/+'
|
112
117
|
config.downlink_url = '/api/v1/users/{username}/apps/{appid}/devices/{deveui}/downlink/post/reply/{clientid}/id/{requestid}'
|
118
|
+
config.downlink_response_urls = {
|
119
|
+
queued: 'reply/{clientid}/id/{requestid}',
|
120
|
+
transmitted: '/sub/v1/users/{username}/apps/{appid}/devices/{deveui}/events/downlink'
|
121
|
+
}
|
113
122
|
config.ssl = true
|
114
123
|
config.ssl_file = 'ssl_certificates/mqtt_ca.crt'
|
115
124
|
end
|
data/lib/config/config.rb
CHANGED
@@ -12,6 +12,10 @@ 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.downlink_response_urls = {
|
16
|
+
queued: 'reply/{clientid}/id/{requestid}',
|
17
|
+
transmitted: '/sub/v1/users/{username}/apps/{appid}/devices/{deveui}/events/downlink'
|
18
|
+
}
|
15
19
|
config.ssl = true
|
16
20
|
config.ssl_file = 'ssl_certificates/mqtt_ca.crt'
|
17
21
|
end
|
data/lib/core/configuration.rb
CHANGED
@@ -2,13 +2,15 @@ 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, :ssl, :ssl_file, :env
|
5
|
+
attr_accessor :protocol, :host, :port, :uplink_url, :downlink_url, :downlink_response_urls, :ssl, :ssl_file, :env
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@protocol = nil
|
9
9
|
@host = nil
|
10
10
|
@port = nil
|
11
|
-
@
|
11
|
+
@uplink_url = nil
|
12
|
+
@downlink_url = nil
|
13
|
+
@downlink_response_urls = nil
|
12
14
|
@ssl = nil # True if uses tls
|
13
15
|
@ssl_file = nil # The certificate's path
|
14
16
|
@env = 'development'
|
data/lib/lora-rb/base.rb
CHANGED
@@ -16,6 +16,9 @@ class LoraClient
|
|
16
16
|
port: LoraRb.configuration.port,
|
17
17
|
uplink_url: LoraRb.configuration.uplink_url,
|
18
18
|
downlink_url: LoraRb.configuration.downlink_url,
|
19
|
+
downlink_response_urls: LoraRb.configuration.downlink_response_urls,
|
20
|
+
username: LoraRb::Settings.username,
|
21
|
+
password: LoraRb::Settings.password,
|
19
22
|
ssl: LoraRb.configuration.ssl,
|
20
23
|
ssl_file: LoraRb.configuration.ssl_file
|
21
24
|
}.merge(options)
|
data/lib/lora-rb/mqtt/call.rb
CHANGED
@@ -10,15 +10,18 @@ module LoraRb
|
|
10
10
|
def sub_initialize(options={})
|
11
11
|
require 'mqtt'
|
12
12
|
|
13
|
-
raise 'Specify
|
14
|
-
raise 'Specify
|
15
|
-
raise 'Specify
|
16
|
-
raise 'Specify
|
13
|
+
raise 'Specify uplink_url to continue!' unless options[:uplink_url]
|
14
|
+
raise 'Specify downlink_url to continue!' unless options[:downlink_url]
|
15
|
+
raise 'Specify downlink_response_urls to continue!' unless options[:downlink_response_urls]
|
16
|
+
raise 'Specify host to continue!' unless options[:host]
|
17
|
+
raise 'Specify port to continue!' unless options[:port]
|
18
|
+
raise 'Specify username to continue!' unless options[:username]
|
19
|
+
raise 'Specify password to continue!' unless options[:password]
|
17
20
|
raise 'Specify ssl_file to continue!' if options[:ssl] && !options[:ssl_file]
|
18
21
|
|
19
|
-
@username =
|
20
|
-
password = LoraRb::Settings.password
|
22
|
+
@username = options[:username]
|
21
23
|
@client_id = "#{@username}::ssg#{generate_request_id}"
|
24
|
+
@downlink_response_urls = options[:downlink_response_urls]
|
22
25
|
|
23
26
|
@client = MQTT::Client.connect(
|
24
27
|
host: options[:host],
|
@@ -26,7 +29,7 @@ module LoraRb
|
|
26
29
|
ssl: options[:ssl],
|
27
30
|
cert_file: options[:ssl_file],
|
28
31
|
username: @username,
|
29
|
-
password: password,
|
32
|
+
password: options[:password],
|
30
33
|
client_id: @client_id
|
31
34
|
)
|
32
35
|
|
@@ -69,31 +72,41 @@ module LoraRb
|
|
69
72
|
puts "#{Time.now} publish #{h_request.to_json} to #{publish_url}" if options[:debug]
|
70
73
|
|
71
74
|
|
72
|
-
|
75
|
+
responses = []
|
76
|
+
thr_responses = []
|
73
77
|
if options[:wait_response]
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
@downlink_response_urls.each do |name, response_url|
|
79
|
+
# response_topic = "reply/#{@client_id}/id/#{request_id}"
|
80
|
+
response_topic = merge_tags_to_url(response_url,
|
81
|
+
username: @username,
|
82
|
+
appid: @appid,
|
83
|
+
deveui: options[:eui],
|
84
|
+
clientid: @client_id,
|
85
|
+
requestid: request_id)
|
86
|
+
puts " [x] Starting thread #{name} to wait response on topic #{response_topic} ..." if options[:debug] == :full
|
87
|
+
thr_responses << Thread.new do
|
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
|
93
|
+
end
|
78
94
|
end
|
79
95
|
|
80
|
-
|
96
|
+
@client.publish(publish_url, h_request.to_json, false)
|
81
97
|
|
82
98
|
if options[:wait_response]
|
83
|
-
# Waiting for the
|
84
|
-
thr_response.join
|
85
|
-
puts " [x] Topic response: #{response}" if options[:debug]
|
86
|
-
else
|
87
|
-
puts " [x] Publish response: #{response}" if options[:debug]
|
99
|
+
# Waiting for all the responses
|
100
|
+
thr_responses.each { |thr_response| thr_response.join }
|
88
101
|
end
|
89
|
-
|
102
|
+
responses
|
90
103
|
end
|
91
104
|
|
92
105
|
# Receive the payload from the network
|
93
106
|
def sub_read_data(options={})
|
94
107
|
topic = options[:topic] || @topic
|
95
108
|
puts " [x] Reading topic #{topic}..." if options[:debug]
|
96
|
-
topic, message = @client.get(topic)
|
109
|
+
topic, message = @client.get(topic.dup)
|
97
110
|
message = JSON.parse(message)
|
98
111
|
if message.respond_to? '[]'
|
99
112
|
message['eui'] ||= get_eui_from_topic(topic)
|
@@ -108,7 +121,7 @@ module LoraRb
|
|
108
121
|
topic = options[:topic] || @topic
|
109
122
|
puts " [*] Waiting for messages in #{topic}. To exit press CTRL+C" if options[:debug]
|
110
123
|
|
111
|
-
@client.get(topic) do |topic, message|
|
124
|
+
@client.get(topic.dup) do |topic, message|
|
112
125
|
# Block is executed for every message received
|
113
126
|
puts " [x] #{topic}: #{message}" if options[:debug]
|
114
127
|
message = JSON.parse(message)
|
data/lib/version.rb
CHANGED