lora-rb 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e06d7a345ef9d3fbd6d15f3b83def826bb7b1d
4
- data.tar.gz: 342d7271ad93a511afb6d961b24a98c7622ca82e
3
+ metadata.gz: fa20e294270b6a37671b7d98b8afe2d70f19ea1f
4
+ data.tar.gz: 5510af9e4a7d1a0ffe716531ae595a4680812905
5
5
  SHA512:
6
- metadata.gz: 57bdf6e6a7a1f395ac9000a0c579999e6932c542e77f42b9abadd2e14753f20a499f7c26a5e0751d00819a3e8062bf1cc203fb0e4efc759b2daa74a9d0d1ae7d
7
- data.tar.gz: b73ce87d688ea98f6760ef2e92275ac384496e3d2443b8681db4f1544b0d633609a7bf0455e3e8a61554f4277c41065c691674fea28ec1ebd39227d3f4e48e40
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
- 1. TLS protocol with [Loriot](http://loriot.io)
29
- 1. Http push with [Resiot](http://resiot.io)
30
- 1. MQTT with [A2aSmartCity](http://www.a2asmartcity.io/)
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
@@ -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
- @url = nil
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)
@@ -10,15 +10,18 @@ module LoraRb
10
10
  def sub_initialize(options={})
11
11
  require 'mqtt'
12
12
 
13
- raise 'Specify aaa to continue!' unless options[:uplink_url]
14
- raise 'Specify aaa to continue!' unless options[:downlink_url]
15
- raise 'Specify aaa to continue!' unless options[:host]
16
- raise 'Specify aaa to continue!' unless options[:port]
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 = LoraRb::Settings.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
- response = nil
75
+ responses = []
76
+ thr_responses = []
73
77
  if options[:wait_response]
74
- response_topic = "reply/#{@client_id}/id/#{request_id}"
75
- puts " [x] Starting thread to wait response on topic #{response_topic} ..." if options[:debug]
76
- thr_response = Thread.new { response_topic, response = sub_read_data(topic: response_topic) }
77
- #sleep 0.1
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
- response = @client.publish(publish_url, h_request.to_json, false)
96
+ @client.publish(publish_url, h_request.to_json, false)
81
97
 
82
98
  if options[:wait_response]
83
- # Waiting for the response
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
- response
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
@@ -1,5 +1,5 @@
1
1
  module LoraRb
2
2
  def self.version
3
- "0.10.0"
3
+ "0.11.0"
4
4
  end
5
5
  end
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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Mastrodonato