mqtt-sub_handler 0.1.6.4 → 0.1.6.5
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 +5 -5
- data/lib/mqtt/base_handler.rb +10 -19
- data/lib/mqtt/sub_handler.rb +13 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b63292ef3dbfdfb64cd76e98da11ea6b23c916c
|
4
|
+
data.tar.gz: 1db5486954346b4f8e09bc807a95b4e578ceac77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 527c14a9c9c9fd67c7d93607b5bed6ee7bf4b8f29145c52ff2829bb2fea903a2ca1fe089234c7471ce538b9d6513367042028fecb1fab7c397dfe43ddc960ec3
|
7
|
+
data.tar.gz: 1ac7f34fe0adeef751bddbc568fad12160eec2c71c4d449791b041091b4c1855429976d1942a327aa43bd9b513386c994c73e80e319e483f1dfbf786b6380220
|
data/lib/mqtt/base_handler.rb
CHANGED
@@ -62,10 +62,10 @@ module MQTT
|
|
62
62
|
h.offer(tMatch, data)
|
63
63
|
}
|
64
64
|
rescue Timeout::Error
|
65
|
-
|
65
|
+
x_loge("Timeout on callback #{h}");
|
66
66
|
rescue => e
|
67
67
|
x_logf("Uncaught error on #{h}");
|
68
|
-
x_logf(e);
|
68
|
+
x_logf(e.inspect);
|
69
69
|
end
|
70
70
|
topicHasReceivers = true;
|
71
71
|
end
|
@@ -82,7 +82,7 @@ module MQTT
|
|
82
82
|
@packetQueueMutex.synchronize {
|
83
83
|
@packetQueue << data;
|
84
84
|
if(@packetQueue.size == 999)
|
85
|
-
|
85
|
+
x_logf("Packet queue congested, dropping packets!");
|
86
86
|
end
|
87
87
|
if(@packetQueue.size > 1000)
|
88
88
|
@packetQueue.shift
|
@@ -196,7 +196,7 @@ module MQTT
|
|
196
196
|
end
|
197
197
|
rescue MQTT::Exception, SocketError, SystemCallError, Timeout::Error => e
|
198
198
|
x_loge("Push error!");
|
199
|
-
x_loge(e.
|
199
|
+
x_loge(e.inspect);
|
200
200
|
|
201
201
|
sleep 0.5
|
202
202
|
end
|
@@ -218,6 +218,7 @@ module MQTT
|
|
218
218
|
x_logi("Connected!");
|
219
219
|
@conChangeMutex.synchronize {
|
220
220
|
@connected = true;
|
221
|
+
@reconnectCount = 0;
|
221
222
|
}
|
222
223
|
|
223
224
|
@packetQueueMutex.synchronize {
|
@@ -231,10 +232,11 @@ module MQTT
|
|
231
232
|
rescue MQTT::Exception, Timeout::Error, SocketError, SystemCallError
|
232
233
|
x_loge("Disconnected!") if @connected
|
233
234
|
@connected = false;
|
235
|
+
@reconnectCount += 1;
|
234
236
|
|
235
237
|
@conChangeMutex.unlock if @conChangeMutex.owned?
|
236
238
|
@mqtt.clean_session = false;
|
237
|
-
sleep
|
239
|
+
sleep [0.1, 0.5, 1, 1, 5, 5, 5, 10, 10, 10, 10][@reconnectCount] || 30;
|
238
240
|
end
|
239
241
|
end
|
240
242
|
|
@@ -242,18 +244,6 @@ module MQTT
|
|
242
244
|
end
|
243
245
|
private :mqtt_resub_thread
|
244
246
|
|
245
|
-
# Pause the main thread and wait for messages.
|
246
|
-
# This is mainly useful when the code has set everything up, but doesn't just want to end.
|
247
|
-
# "INT" is trapped, ensuring a smooth exit on Ctrl-C
|
248
|
-
def lockAndListen()
|
249
|
-
Signal.trap("INT") {
|
250
|
-
exit 0
|
251
|
-
}
|
252
|
-
|
253
|
-
puts "Main thread paused."
|
254
|
-
Thread.stop();
|
255
|
-
end
|
256
|
-
|
257
247
|
def destroy!()
|
258
248
|
return if @destroying
|
259
249
|
@destroying = true;
|
@@ -268,7 +258,7 @@ module MQTT
|
|
268
258
|
end
|
269
259
|
}
|
270
260
|
rescue Timeout::Error
|
271
|
-
x_logw "
|
261
|
+
x_logw "Not all messages were published";
|
272
262
|
else
|
273
263
|
x_logd "Publish clean finished"
|
274
264
|
end
|
@@ -308,7 +298,8 @@ module MQTT
|
|
308
298
|
self.log_level = Logger::INFO;
|
309
299
|
|
310
300
|
@conChangeMutex = Mutex.new();
|
311
|
-
@connected
|
301
|
+
@connected = false;
|
302
|
+
@reconnectCount = 0;
|
312
303
|
|
313
304
|
@mqtt.client_id ||= MQTT::Client.generate_client_id("MQTT_Sub_", 8);
|
314
305
|
|
data/lib/mqtt/sub_handler.rb
CHANGED
@@ -124,6 +124,19 @@ class SubHandler < BaseHandler
|
|
124
124
|
end
|
125
125
|
alias publishTo publish_to
|
126
126
|
|
127
|
+
# Pause the main thread and wait for messages.
|
128
|
+
# This is mainly useful when the code has set everything up, but doesn't just want to end.
|
129
|
+
# "INT" is trapped, ensuring a smooth exit on Ctrl-C
|
130
|
+
def lockAndListen()
|
131
|
+
Signal.trap("INT") {
|
132
|
+
exit 0
|
133
|
+
}
|
134
|
+
|
135
|
+
x_logi("Main thread paused.")
|
136
|
+
Thread.stop();
|
137
|
+
end
|
138
|
+
alias lock_and_listen lockAndListen
|
139
|
+
|
127
140
|
def initialize(mqttClient, jsonify: true)
|
128
141
|
super(mqttClient);
|
129
142
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqtt-sub_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.6.
|
4
|
+
version: 0.1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xasin
|
@@ -129,7 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
|
-
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.5.2.1
|
133
134
|
signing_key:
|
134
135
|
specification_version: 4
|
135
136
|
summary: Asynchronous, topic-based MQTT gem
|