lora-rb 0.9.3 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79c6d0b8da60562e095fecb4d8c78b436a1a4e92
4
- data.tar.gz: 7629b1d3970c241e5d9a0e275aec3c966d859510
3
+ metadata.gz: 93e06d7a345ef9d3fbd6d15f3b83def826bb7b1d
4
+ data.tar.gz: 342d7271ad93a511afb6d961b24a98c7622ca82e
5
5
  SHA512:
6
- metadata.gz: 3fb99d9ed59893102df187a271e0bc8dc0fe9c0c81e09f329e3759a6e0a4ab2b81f37b255fbc12c59ad5ceb0a90ba0923a188be79ffab2a52b3b1022e876bc9d
7
- data.tar.gz: 46256d4883731154991c811ac96ab6f224d08f0934dcf7826d3e2a71e4744b00c2230c06e9e6947f9888b0b6aa6b2214b721f3d0b143a4723f7c7a9a9f346e2e
6
+ metadata.gz: 57bdf6e6a7a1f395ac9000a0c579999e6932c542e77f42b9abadd2e14753f20a499f7c26a5e0751d00819a3e8062bf1cc203fb0e4efc759b2daa74a9d0d1ae7d
7
+ data.tar.gz: b73ce87d688ea98f6760ef2e92275ac384496e3d2443b8681db4f1544b0d633609a7bf0455e3e8a61554f4277c41065c691674fea28ec1ebd39227d3f4e48e40
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.10.0 [☰](https://bitbucket.org/fractalgarden/loriot-rb/branches/compare/v0.9.0..v0.10.0) August 8th, 2017
2
+ ------------------------------
3
+ * Mqtt:
4
+ * added multi threading support
5
+ * send_cmd now set wait_response: true by default. With this param, the response is waited using a separate thread
6
+
1
7
  v0.9.3 August 8th, 2017
2
8
  ------------------------------
3
9
  * Fixed a bug with mqtt protocol: now when LoraClient is instantiated uses the new client id just generated
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # IOT at you service with LoraWan and Ruby
2
- ### Manage your devices inside a Lora Network
1
+ # IOT at you service with Lora and Ruby
2
+ ### Manage your devices under the Lora Network
3
3
 
4
4
  [![Version ](https://badge.fury.io/rb/lora-rb.svg) ](https://rubygems.org/gems/lora-rb)
5
5
  [![Travis CI ](http://img.shields.io/travis/marcomd/lora-rb/master.svg) ](https://travis-ci.org/marcomd/lora-rb)
@@ -21,7 +21,8 @@ To use it in a bundle, add to gem file `gem 'lora-rb'` and run `bundle install`
21
21
 
22
22
  ## Connection to lora server
23
23
 
24
- Establish a secure connection to your `Lora Application` on the cloud.
24
+ To use this gem you have to choose your provider. Each of them has its own features and offers a bouquet of protocols
25
+ among which you can choose to connect to the lora network.
25
26
 
26
27
  This version supports:
27
28
  1. TLS protocol with [Loriot](http://loriot.io)
@@ -30,11 +31,11 @@ This version supports:
30
31
 
31
32
  ## Configuration
32
33
 
33
- Insert private information in the yaml:
34
+ Insert private informations in the yaml:
34
35
 
35
36
  lib/config/private.yml
36
37
 
37
- and the configuration's parameter in the config file.
38
+ and the configuration's parameters in the config file.
38
39
 
39
40
  lib/config/config.rb
40
41
 
@@ -42,7 +43,9 @@ If you are using rails you can use the generator:
42
43
 
43
44
  bundle exec rails generate lora_rb:install
44
45
 
45
- Every provider assign you a token and an appkey or an appid. Insert your secret data in the yaml:
46
+ Every provider assign you a token and an app id.
47
+ Someone can provide some additional parameters such as username and password.
48
+ Insert your secret data in the yaml:
46
49
 
47
50
  ```yaml
48
51
  defaults:
@@ -54,7 +57,8 @@ defaults:
54
57
  connector_id:
55
58
  ```
56
59
 
57
- If you are using Rails 5.1 you can do something like this:
60
+ If you are using Rails 5.1 you can encrypt these private data and insert into the yaml with erb.
61
+ Something like this:
58
62
 
59
63
  ```yaml
60
64
  defaults: &defaults
@@ -63,11 +67,15 @@ defaults: &defaults
63
67
  # etc ...
64
68
  ```
65
69
 
70
+ ## Connection's protocols
71
+
72
+ While the information in the yaml file is subdivided by environment, the connection configuration file contains
73
+ shared parameters for all environments.
74
+
66
75
  ### TLS (with Loriot)
67
76
 
68
77
  ```ruby
69
78
  LoraRb.configure do |config|
70
- # These informations are shared for all environments
71
79
  config.protocol = :tls
72
80
  config.host = 'eu1.loriot.io'
73
81
  config.port = 737
@@ -78,7 +86,6 @@ end
78
86
 
79
87
  ```ruby
80
88
  LoraRb.configure do |config|
81
- # These informations are shared for all environments
82
89
  config.protocol = :http
83
90
  config.host = 'eu72.resiot.io'
84
91
  config.port = 80
@@ -89,7 +96,6 @@ end
89
96
 
90
97
  ```ruby
91
98
  LoraRb.configure do |config|
92
- # These informations are shared for all environments
93
99
  config.protocol = :rabbitmq
94
100
  config.host = 'localhost'
95
101
  end
@@ -99,7 +105,6 @@ end
99
105
 
100
106
  ```ruby
101
107
  LoraRb.configure do |config|
102
- # These informations are shared for all environments
103
108
  config.protocol = :mqtt
104
109
  config.host = 'ptnetsuite.a2asmartcity.io'
105
110
  config.port = 8883
@@ -130,34 +135,69 @@ you should receive the instance with variables depending on protocol:
130
135
  #<LoraClient:0x0056318ad8e048 ...
131
136
  ```
132
137
 
133
- ### Send data to a device
138
+ ### Downlink: send data to the device
134
139
 
135
140
 
136
141
  ```ruby
137
- lora.send_cmd(EUI: 'Insert here your EUI code', confirmed: true, data: "0101")
142
+ lora.send_cmd(eui: 'Insert here your device eui', confirmed: true, data: '0101')
138
143
  ```
139
144
 
140
- Request example:
145
+ The response depend on the provider.
146
+ This is an example using tls protocol and the provider Loriot.io:
141
147
 
142
148
  ```json
143
- { "cmd":"tx", "EUI":"BE7A0000000010B7", "port":40, "confirmed":false, "data":"0101" }
149
+ { "cmd":"tx", "EUI":"a000000000001234", "port":40, "confirmed":false, "data":"0101" }
144
150
  ```
145
151
 
146
- Response example:
152
+ or
147
153
 
148
154
  ```json
149
- { "cmd":"txd", "EUI":"BE7A0000000010B7", "seqdn":114, "seqq":113, "ts":1489133179385 }
155
+ { "cmd":"txd", "EUI":"a000000000001234", "seqdn":114, "seqq":113, "ts":1489133179385 }
150
156
  ```
151
157
 
152
- `"cmd":"txd"` show the data sent to the gateway
158
+ or
159
+
160
+ ```json
161
+ { "cmd":"tx", "EUI":"a000000000001234", "seqdn": 4, "data": "0301", "success": "Data enqueued" }
162
+ ```
163
+
164
+ This is an example using http protocol and the provider Resiot.io
165
+
166
+ ```json
167
+ {
168
+ "CommType"=>"comm_rx",
169
+ "Connector"=>"69643d32",
170
+ "AppEui"=>"a1b2c3d4e5f60001",
171
+ "DevEui"=>"be7a00000000123c",
172
+ "Port"=>"10",
173
+ "GatewayEUIs"=>["00000111180e2222"],
174
+ "Payload"=>"0063",
175
+ "Extra"=>{"JSONRXINFO"=>"[\"{\\\"altitude\\\":0,\\\"latitude\\\":0,\\\"loRaSNR\\\":8.8,\\\"longitude\\\":0,\\\"mac\\\":\\\"00000111180e2222\\\",\\\"name\\\":\\\"00000111180e2222\\\",\\\"rssi\\\":-67}\"]",
176
+ "adr"=>"true", "bandwidth"=>"125", "fCnt"=>"132", "frequency"=>"868100000", "spreadFactor"=>"7"},
177
+ "DT"=>"2017-07-03T15:28:01.098886848+02:00",
178
+ "auth_token"=>"abcd1234",
179
+ "lora"=>{"CommType"=>"comm_rx", "Connector"=>"abcd", "AppEui"=>"abcd", "DevEui"=>"a000000000001234", "Port"=>"10", "GatewayEUIs"=>["abcd"], "Payload"=>"0063",
180
+ "Extra"=>{"JSONRXINFO"=>"[\"{\\\"altitude\\\":0,\\\"latitude\\\":0,\\\"loRaSNR\\\":8.8,\\\"longitude\\\":0,\\\"mac\\\":\\\"00000111180e2222\\\",\\\"name\\\":\\\"00000111180e2222\\\",\\\"rssi\\\":-67}\"]", "adr"=>"true", "bandwidth"=>"125", "fCnt"=>"132", "frequency"=>"868100000", "spreadFactor"=>"7"}, "DT"=>"2017-07-03T15:28:01.098886848+02:00"}
181
+ }
182
+ ```
153
183
 
154
- The response could also be:
184
+ This is an example provided using mqtt protocol and the provider A2a:
155
185
 
156
186
  ```json
157
- { "cmd":"tx", "EUI":"BE7A0000000010CF", "seqdn": 4, "data": "0301", "success": "Data enqueued" }
187
+ {"reply"=>{"confirmed"=>false, "id"=>150, "payload"=>"0100", "port"=>40, "priority"=>0}, "status"=>200, "eui"=>nil, "port"=>nil}
158
188
  ```
159
189
 
160
- ### Receive Data
190
+ Using MQTT, by default the param wait_response is true. This means after publishing a message it waits the response
191
+ on dedicated topic.
192
+ If you dont want to wait the response you just set that param to false.
193
+
194
+ ```ruby
195
+ lora.send_cmd(eui: 'Insert here your device eui',
196
+ data: 'f0a1b3ff',
197
+ wait_response: false)
198
+ ```
199
+
200
+ ### Uplink: receive data from devices
161
201
 
162
202
  To listen your devices:
163
203
 
@@ -165,6 +205,39 @@ To listen your devices:
165
205
  lora.listen
166
206
  ```
167
207
 
208
+ You can also pass a block.
209
+
210
+ ```ruby
211
+ lora.listen do |response|
212
+ # Do something ...
213
+ end
214
+ ```
215
+
216
+ or with RabbitMq:
217
+
218
+ ```ruby
219
+ lora.listen do |delivery_info, properties, body|
220
+ # Do something ...
221
+ end
222
+ ```
223
+
224
+ or with mqtt protocol:
225
+
226
+ ```ruby
227
+ lora.listen do |topic, response|
228
+ # Do something ...
229
+ end
230
+ ```
231
+
232
+ Using http protocol, instead, #listen is not available because uplink messages are received by api.
233
+
234
+ To receive only one message:
235
+
236
+ ```ruby
237
+ lora.read_data
238
+ ```
239
+ It returns the same data of listen method.
240
+
168
241
  ### Close the connection
169
242
 
170
243
  ```ruby
@@ -36,11 +36,13 @@ module LoraRb
36
36
  { debug: options[:debug] })
37
37
 
38
38
  @downlink_url = merge_tags_to_url(options[:downlink_url])
39
+ @wait_response = options.has_key?(:wait_response) ? options[:wait_response] : true
39
40
  {'hello' => 'Lora-Rb: Ready to start!'}
40
41
  end
41
42
 
42
43
  # Send the request to device
43
44
  def sub_send_cmd(options={})
45
+ options = { wait_response: @wait_response }.merge(options)
44
46
  h_request = {
45
47
  "port": options[:port], # Port where the message should be sent
46
48
  "payload": options[:data], # Message payload
@@ -66,14 +68,23 @@ module LoraRb
66
68
 
67
69
  puts "#{Time.now} publish #{h_request.to_json} to #{publish_url}" if options[:debug]
68
70
 
69
- response = @client.publish(publish_url, h_request.to_json, false)
70
- puts " [x] publish response: #{response}" if options[:debug]
71
71
 
72
+ response = nil
72
73
  if options[:wait_response]
73
74
  response_topic = "reply/#{@client_id}/id/#{request_id}"
74
- puts " [x] Waiting response on #{response_topic} ..." if options[:debug]
75
- response_topic, response = sub_read_data(topic: response_topic)
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
+ end
79
+
80
+ response = @client.publish(publish_url, h_request.to_json, false)
81
+
82
+ if options[:wait_response]
83
+ # Waiting for the response
84
+ thr_response.join
76
85
  puts " [x] Topic response: #{response}" if options[:debug]
86
+ else
87
+ puts " [x] Publish response: #{response}" if options[:debug]
77
88
  end
78
89
  response
79
90
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module LoraRb
2
2
  def self.version
3
- "0.9.3"
3
+ "0.10.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.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Mastrodonato