losant_mqtt 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.markdownlint.json +10 -0
- data/.ruby-version +1 -1
- data/.travis.yml +6 -4
- data/LICENSE +1 -1
- data/README.md +37 -49
- data/lib/losant_mqtt.rb +1 -1
- data/lib/losant_mqtt/device.rb +1 -1
- data/lib/losant_mqtt/device_connection.rb +1 -1
- data/lib/losant_mqtt/utils.rb +1 -1
- data/lib/losant_mqtt/version.rb +2 -2
- data/losant_mqtt.gemspec +2 -2
- data/spec/device_spec.rb +16 -8
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95e1102a26f7a342a937e14265699b57143aeb4d3e0596e133662acd0aad3bf3
|
4
|
+
data.tar.gz: 538c22dc7d4e8c95c54d007239dd274ed520017552c1bcb54a2eb9479673c157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 150f8fbb01168707d750f965093e78a774fc0f9c5f4a052a25f03e46b3e16a02555afde857c449bcf5c1047d6417e4d13cfd93fefdca2a9227eecefeac59b2cf
|
7
|
+
data.tar.gz: addfbc387818cdbb17b10cce44b1a795c924a57e1205553f75c999352bfb83055ead97ead5e1bb728cc434732c069899abdbe2b808a74a303b400b3a1077f468
|
data/.markdownlint.json
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.0
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/Losant/losant-mqtt-ruby.svg?branch=master)](https://travis-ci.org/Losant/losant-mqtt-ruby) [![Gem Version](https://badge.fury.io/rb/losant_mqtt.svg)](https://badge.fury.io/rb/losant_mqtt)
|
4
4
|
|
5
5
|
The [Losant](https://www.losant.com) MQTT client provides a simple way for
|
6
|
-
custom things to communicate with the Losant platform over MQTT.
|
6
|
+
custom things to communicate with the Losant platform over MQTT. You can
|
7
7
|
authenticate as a device, publish device state, and listen for device commands.
|
8
8
|
|
9
9
|
This client works with Ruby 2.1 and higher, and it depends on [Event Machine](https://github.com/eventmachine/eventmachine) to provide
|
@@ -75,15 +75,15 @@ end
|
|
75
75
|
|
76
76
|
## API Documentation
|
77
77
|
|
78
|
-
*
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
* [Device](#device)
|
79
|
+
* [initializer](#initializer)
|
80
|
+
* [connect](#connect)
|
81
|
+
* [connected?](#connected)
|
82
|
+
* [close](#close)
|
83
|
+
* [send_state](#send_state)
|
84
|
+
* [on](#on)
|
85
|
+
* [add_listener](#add_listener)
|
86
|
+
* [remove_listener](#remove_listener)
|
87
87
|
|
88
88
|
### Device
|
89
89
|
|
@@ -111,28 +111,22 @@ LosantMqtt::Device.new(device_id:, key:, secret:, secure: true, retry_lost_conne
|
|
111
111
|
|
112
112
|
The ``Client()`` initializer takes the following arguments:
|
113
113
|
|
114
|
-
*
|
115
|
-
The device's ID. Obtained by first registering a device using
|
116
|
-
the Losant platform.
|
114
|
+
* device_id
|
115
|
+
The device's ID. Obtained by first registering a device using the Losant platform.
|
117
116
|
|
118
|
-
*
|
119
|
-
The Losant access key.
|
117
|
+
* key
|
118
|
+
The Losant access key.
|
120
119
|
|
121
|
-
*
|
122
|
-
The Losant access secret.
|
120
|
+
* secret
|
121
|
+
The Losant access secret.
|
123
122
|
|
124
|
-
*
|
125
|
-
If the client should connect to Losant over SSL - default is true.
|
123
|
+
* secure
|
124
|
+
If the client should connect to Losant over SSL - default is true.
|
126
125
|
|
127
|
-
*
|
128
|
-
If the client should retry lost connections - default is true.
|
129
|
-
initial connect will still be raised, but if a good connection is
|
130
|
-
subsequently lost and this flag is true, the client will try to automatically
|
131
|
-
reconnect and will not raise errors (except in the case of authentication
|
132
|
-
errors, which will still be raised). When this flag is true, disconnection
|
133
|
-
and reconnection can be monitored using the `:close` and `:reconnect` events.
|
126
|
+
* retry_lost_connection
|
127
|
+
If the client should retry lost connections - default is true. Errors on initial connect will still be raised, but if a good connection is subsequently lost and this flag is true, the client will try to automatically reconnect and will not raise errors (except in the case of authentication errors, which will still be raised). When this flag is true, disconnection and reconnection can be monitored using the `:close` and `:reconnect` events.
|
134
128
|
|
135
|
-
|
129
|
+
##### Initializer Example
|
136
130
|
|
137
131
|
```ruby
|
138
132
|
device = LosantMqtt::Device.new(device_id: "my-device-id",
|
@@ -178,13 +172,13 @@ coordinates once a second or more. Because of this, sendState is typically
|
|
178
172
|
the most invoked function. Any state data sent to Losant is stored and made
|
179
173
|
available in data visualization tools and workflow triggers.
|
180
174
|
|
181
|
-
*
|
182
|
-
The state to send as a hash.
|
175
|
+
* state
|
176
|
+
The state to send as a hash.
|
183
177
|
|
184
|
-
*
|
185
|
-
When the state
|
178
|
+
* time
|
179
|
+
When the state occurred - if nil or not set, will default to now.
|
186
180
|
|
187
|
-
|
181
|
+
##### Send State Example
|
188
182
|
|
189
183
|
```ruby
|
190
184
|
device.send_state({ voltage: read_analog_in() })
|
@@ -198,20 +192,14 @@ on(event, proc=nil, &block)
|
|
198
192
|
|
199
193
|
Adds an observer to listen for an event on this device.
|
200
194
|
|
201
|
-
*
|
202
|
-
The event name to listen for.
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
* proc / &block
|
208
|
-
The proc or block to call with the given event fires. The first
|
209
|
-
argument for all callbacks will be the device instance. For `:close` callbacks,
|
210
|
-
there can be a second argument which is the reason for the closing of the
|
211
|
-
connection, and for `:command` callbacks the second argument is the command
|
195
|
+
* event
|
196
|
+
The event name to listen for. Possible events are: `:connect` (the device has connected), `:reconnect` (the device lost its connection and reconnected), `:close` (the device's connection was closed), and `:command` (the device has received a command from Losant).
|
197
|
+
|
198
|
+
* proc / &block
|
199
|
+
The proc or block to call with the given event fires. The first argument for all callbacks will be the device instance. For `:close` callbacks, there can be a second argument which is the reason for the closing of the connection, and for `:command` callbacks the second argument is the command
|
212
200
|
received.
|
213
201
|
|
214
|
-
|
202
|
+
##### On Command Example
|
215
203
|
|
216
204
|
```ruby
|
217
205
|
device.on(:command) do |device, command|
|
@@ -233,16 +221,16 @@ remove_listener(event, proc)
|
|
233
221
|
|
234
222
|
Removes an observer from listening for an event on this device.
|
235
223
|
|
236
|
-
*
|
237
|
-
The event name to stop listening for.
|
224
|
+
* event
|
225
|
+
The event name to stop listening for. Same events as [on](#on).
|
238
226
|
|
239
|
-
*
|
240
|
-
The proc that should be removed.
|
227
|
+
* proc
|
228
|
+
The proc that should be removed.
|
241
229
|
|
242
230
|
<br/>
|
243
231
|
|
244
232
|
*****
|
245
233
|
|
246
|
-
Copyright (c)
|
234
|
+
Copyright (c) 2019 Losant IoT, Inc
|
247
235
|
|
248
236
|
<https://www.losant.com>
|
data/lib/losant_mqtt.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
#
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2019 Losant IoT, Inc.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/losant_mqtt/device.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
#
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2019 Losant IoT, Inc.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
#
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2019 Losant IoT, Inc.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/losant_mqtt/utils.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
#
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2019 Losant IoT, Inc.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/losant_mqtt/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
#
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2019 Losant IoT, Inc.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -21,5 +21,5 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
module LosantMqtt
|
24
|
-
VERSION = "1.0.
|
24
|
+
VERSION = "1.0.2"
|
25
25
|
end
|
data/losant_mqtt.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.required_ruby_version = ">= 2.1"
|
19
19
|
|
20
20
|
gem.add_runtime_dependency "eventmachine", "~> 1.2"
|
21
|
-
gem.add_runtime_dependency "mqtt", "~> 0.
|
21
|
+
gem.add_runtime_dependency "mqtt", "~> 0.5"
|
22
22
|
gem.add_runtime_dependency "events", "~> 0.9"
|
23
23
|
|
24
|
-
gem.add_development_dependency "rspec", "~> 3.
|
24
|
+
gem.add_development_dependency "rspec", "~> 3.8"
|
25
25
|
gem.add_development_dependency "rake", "~> 12"
|
26
26
|
end
|
data/spec/device_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe LosantMqtt::Device do
|
|
18
18
|
|
19
19
|
it "should correctly connect, send state, and receive a command" do
|
20
20
|
EventMachine.run do
|
21
|
-
EventMachine.add_timer(
|
21
|
+
EventMachine.add_timer(15) { raise RuntimeError.new("Test Timed Out") }
|
22
22
|
|
23
23
|
# associated with app id 57615eebc035bd0100cb964a
|
24
24
|
# workflow that takes state reported and sends a command back
|
@@ -35,7 +35,9 @@ describe LosantMqtt::Device do
|
|
35
35
|
callbacks_called.push(:command)
|
36
36
|
expect(cmd["name"]).to eq("triggeredCommand")
|
37
37
|
expect(cmd["payload"]).to eq({ "result" => "one-1-false" })
|
38
|
-
|
38
|
+
EventMachine.add_timer(0.1) do
|
39
|
+
d.close
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
43
|
device.on(:connect) do |d|
|
@@ -51,7 +53,9 @@ describe LosantMqtt::Device do
|
|
51
53
|
expect(d.connected?).to eq(false)
|
52
54
|
expect(reason).to eq(nil)
|
53
55
|
expect(callbacks_called).to eq([:connect, :command])
|
54
|
-
EventMachine.
|
56
|
+
EventMachine.add_timer(0.1) do
|
57
|
+
EventMachine.stop_event_loop
|
58
|
+
end
|
55
59
|
end
|
56
60
|
|
57
61
|
device.send_state({ str_attr: "one", num_attr: 1, bool_attr: false })
|
@@ -60,7 +64,7 @@ describe LosantMqtt::Device do
|
|
60
64
|
|
61
65
|
it "should reconnect when connection is abnormally lost and flag is true" do
|
62
66
|
EventMachine.run do
|
63
|
-
EventMachine.add_timer(
|
67
|
+
EventMachine.add_timer(15) { raise RuntimeError.new("Test Timed Out") }
|
64
68
|
|
65
69
|
# associated with app id 57615eebc035bd0100cb964a
|
66
70
|
# workflow that takes state reported and sends a command back
|
@@ -77,7 +81,9 @@ describe LosantMqtt::Device do
|
|
77
81
|
callbacks_called.push(:command)
|
78
82
|
expect(cmd["name"]).to eq("triggeredCommand")
|
79
83
|
expect(cmd["payload"]).to eq({ "result" => "two-2-true" })
|
80
|
-
|
84
|
+
EventMachine.add_timer(0.1) do
|
85
|
+
d.close
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
89
|
device.on(:connect) do |d|
|
@@ -106,7 +112,9 @@ describe LosantMqtt::Device do
|
|
106
112
|
else
|
107
113
|
expect(reason).to eq(nil)
|
108
114
|
expect(callbacks_called).to eq([:connect, :close, :reconnect, :command, :close])
|
109
|
-
EventMachine.
|
115
|
+
EventMachine.add_timer(0.1) do
|
116
|
+
EventMachine.stop_event_loop
|
117
|
+
end
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
@@ -117,7 +125,7 @@ describe LosantMqtt::Device do
|
|
117
125
|
it "should not reconnect when connection is abnormally lost and flag is false" do
|
118
126
|
expect do
|
119
127
|
EventMachine.run do
|
120
|
-
EventMachine.add_timer(
|
128
|
+
EventMachine.add_timer(15) { raise RuntimeError.new("Test Timed Out") }
|
121
129
|
|
122
130
|
# associated with app id 57615eebc035bd0100cb964a
|
123
131
|
# workflow that takes state reported and sends a command back
|
@@ -162,7 +170,7 @@ describe LosantMqtt::Device do
|
|
162
170
|
it "should raise errors on initial bad connect" do
|
163
171
|
expect do
|
164
172
|
EventMachine.run do
|
165
|
-
EventMachine.add_timer(
|
173
|
+
EventMachine.add_timer(15) { raise RuntimeError.new("Test Timed Out") }
|
166
174
|
device = LosantMqtt::Device.new(
|
167
175
|
device_id: "not a device id",
|
168
176
|
key: "not a key",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: losant_mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Kuehl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: events
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.8'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".markdownlint.json"
|
91
92
|
- ".ruby-version"
|
92
93
|
- ".travis.yml"
|
93
94
|
- Gemfile
|
@@ -121,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.6.8
|
125
|
+
rubygems_version: 3.0.1
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: An MQTT client for the Losant MQTT Broker
|