paho-mqtt 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/lib/paho-mqtt.rb +1 -1
- data/lib/paho_mqtt/client.rb +0 -1
- data/lib/paho_mqtt/subscriber.rb +11 -6
- data/lib/paho_mqtt/version.rb +1 -1
- data/samples/client_blocking(writing).rb +7 -5
- data/samples/test_client.rb +29 -32
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e96a49570aa770ba8c03e15a22b3f07dab8c537
|
4
|
+
data.tar.gz: 33be02b618285d8493528df49641583e432398df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19536ea5cd1d728654965db904f9fee6a204afb783979b178b835d735f947199778523c332941fec72dec1d21e6a853c5d2eb91ea45f51cf67119209a2115862
|
7
|
+
data.tar.gz: 285e5abeabd2aabdd9ccc6072da616868b311870e875cfe5cd57f22d80acf766cd9acc4ab961869f73d7fd69b75ab26b487b4def1a6b2af3280b41833aa5d82e
|
data/.gitignore
CHANGED
data/lib/paho-mqtt.rb
CHANGED
data/lib/paho_mqtt/client.rb
CHANGED
data/lib/paho_mqtt/subscriber.rb
CHANGED
@@ -61,12 +61,12 @@ module PahoMqtt
|
|
61
61
|
adjust_qos.delete(t)
|
62
62
|
else
|
63
63
|
|
64
|
-
@logger.error("The qos value is invalid in subscribe.") if logger?
|
64
|
+
@logger.error("The qos value is invalid in subscribe.") if PahoMqtt.logger?
|
65
65
|
raise PacketException
|
66
66
|
end
|
67
67
|
end
|
68
68
|
else
|
69
|
-
@logger.error("The packet id is invalid, already used.") if logger?
|
69
|
+
@logger.error("The packet id is invalid, already used.") if PahoMqtt.logger?
|
70
70
|
raise PacketException
|
71
71
|
end
|
72
72
|
@subscribed_mutex.synchronize {
|
@@ -83,13 +83,13 @@ module PahoMqtt
|
|
83
83
|
if to_unsub.length == 1
|
84
84
|
to_unsub = to_unsub.first[:packet].topics
|
85
85
|
else
|
86
|
-
@logger.error("The packet id is invalid, already used.") if logger?
|
86
|
+
@logger.error("The packet id is invalid, already used.") if PahoMqtt.logger?
|
87
87
|
raise PacketException
|
88
88
|
end
|
89
89
|
|
90
90
|
@subscribed_mutex.synchronize {
|
91
91
|
to_unsub.each do |filter|
|
92
|
-
@subscribed_topics.delete_if { |topic| match_filter(topic.first, filter
|
92
|
+
@subscribed_topics.delete_if { |topic| match_filter(topic.first, filter) }
|
93
93
|
end
|
94
94
|
}
|
95
95
|
MQTT_ERR_SUCCESS
|
@@ -136,7 +136,12 @@ module PahoMqtt
|
|
136
136
|
def valid_topics?(topics)
|
137
137
|
unless topics.length == 0
|
138
138
|
topics.map do |topic|
|
139
|
-
|
139
|
+
case topic
|
140
|
+
when Array
|
141
|
+
return MQTT_ERR_FAIL if topic.first == ""
|
142
|
+
when String
|
143
|
+
return MQTT_ERR_FAIL if topic == ""
|
144
|
+
end
|
140
145
|
end
|
141
146
|
else
|
142
147
|
MQTT_ERR_FAIL
|
@@ -187,7 +192,7 @@ module PahoMqtt
|
|
187
192
|
def check_topics(topics, filters)
|
188
193
|
if topics.is_a?(String) && filters.is_a?(String)
|
189
194
|
else
|
190
|
-
@logger.error("Topics or Wildcards are not found as String.") if logger?
|
195
|
+
@logger.error("Topics or Wildcards are not found as String.") if PahoMqtt.logger?
|
191
196
|
raise ArgumentError
|
192
197
|
end
|
193
198
|
end
|
data/lib/paho_mqtt/version.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'paho-mqtt'
|
2
|
-
require 'logger'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
PahoMqtt.logger = ('paho_mqtt.log')
|
4
|
+
|
5
|
+
client = PahoMqtt::Client.new()
|
6
|
+
|
7
|
+
client.on_message = lambda { |p| puts ">>>>> This is the callback for a message event <<<<<\nTopic: #{p.topic}\nPayload: #{p.payload}\nQoS: #{p.qos}" }
|
7
8
|
|
8
|
-
client = PahoMqtt::Client.new({logger: log})
|
9
9
|
|
10
10
|
client.connect('localhost', 1883, client.keep_alive, true, true)
|
11
|
+
client.subscribe(["topic_test", 2])
|
11
12
|
|
12
13
|
loop do
|
13
14
|
client.publish("topic_test", "Hello, Are you there?", false, 1)
|
14
15
|
client.loop_write
|
16
|
+
client.loop_read
|
15
17
|
sleep 1
|
16
18
|
end
|
data/samples/test_client.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require "paho-mqtt"
|
2
2
|
require "logger"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
log.level = Logger::DEBUG
|
7
|
-
|
8
|
-
cli = PahoMqtt::Client.new({logger: log, persistent: true, keep_alive: 7})
|
4
|
+
cli = PahoMqtt::Client.new({persistent: true, keep_alive: 7})
|
5
|
+
PahoMqtt.logger = ('paho_log')
|
9
6
|
|
10
7
|
cli.connect('localhost', 1883)
|
11
8
|
|
@@ -16,56 +13,56 @@ cli.on_suback { waiting = false}
|
|
16
13
|
|
17
14
|
cli.on_message = lambda { |p| puts ">>>>> This is a LAMBDA callback for message event <<<<<\nTopic: #{p.topic}\nPayload: #{p.payload}\nQoS: #{p.qos}" }
|
18
15
|
|
19
|
-
|
20
|
-
|
16
|
+
foo_foo = lambda { |p| puts ">>>>> I am LAMBDA callback for the /foo/foo topic <<<<<" }
|
17
|
+
foo_bar = proc { puts ">>>>> I am PROC callback for the /foo/bar topic <<<<<" }
|
21
18
|
|
22
19
|
|
23
|
-
cli.add_topic_callback('/
|
24
|
-
puts ">>>>> I am BLOCK callback for the /
|
20
|
+
cli.add_topic_callback('/foo/tutu') do
|
21
|
+
puts ">>>>> I am BLOCK callback for the /foo/tutu topic <<<<<"
|
25
22
|
end
|
26
|
-
cli.add_topic_callback('/
|
27
|
-
cli.add_topic_callback('/
|
23
|
+
cli.add_topic_callback('/foo/bar', foo_bar)
|
24
|
+
cli.add_topic_callback('/foo/foo', foo_foo)
|
28
25
|
|
29
26
|
#########################################################
|
30
27
|
|
31
|
-
cli.subscribe(['/
|
28
|
+
cli.subscribe(['/foo/foo', 0], ['/foo/bar', 1], ['/foo/tutu', 2], ["/foo", 0])
|
32
29
|
|
33
30
|
while waiting do
|
34
31
|
sleep 0.0001
|
35
32
|
end
|
36
33
|
|
37
|
-
cli.publish("/
|
38
|
-
cli.publish("/
|
39
|
-
cli.publish("/
|
34
|
+
cli.publish("/foo/tutu", "It's me!", false, 2)
|
35
|
+
cli.publish("/foo/tutu", "It's you!", false, 1)
|
36
|
+
cli.publish("/foo/tutu", "It's them!", false, 0)
|
40
37
|
|
41
|
-
cli.publish("/
|
42
|
-
cli.publish("/
|
43
|
-
cli.publish("/
|
38
|
+
cli.publish("/foo/bar", "It's me!", false, 2)
|
39
|
+
cli.publish("/foo/bar", "It's you!", false, 1)
|
40
|
+
cli.publish("/foo/bar", "It's them!", false, 0)
|
44
41
|
|
45
|
-
cli.publish("/
|
46
|
-
cli.publish("/
|
47
|
-
cli.publish("/
|
42
|
+
cli.publish("/foo/foo", "It's me!", false, 2)
|
43
|
+
cli.publish("/foo/foo", "It's you!", false, 1)
|
44
|
+
cli.publish("/foo/foo", "It's them!", false, 0)
|
48
45
|
|
49
46
|
sleep cli.ack_timeout
|
50
47
|
|
51
48
|
cli.on_message = nil
|
52
|
-
|
53
|
-
cli.add_topic_callback('/
|
54
|
-
cli.add_topic_callback('/
|
55
|
-
puts ">>>>> Changing callback type to BLOCK for the /
|
49
|
+
foo_tutu = lambda { |p| puts ">>>>> Changing callback type to LAMBDA for the /foo/tutu topic <<<<<" }
|
50
|
+
cli.add_topic_callback('/foo/tutu', foo_tutu)
|
51
|
+
cli.add_topic_callback('/foo/bar') do
|
52
|
+
puts ">>>>> Changing callback type to BLOCK for the /foo/bar topic <<<<<"
|
56
53
|
end
|
57
54
|
|
58
|
-
cli.publish("/
|
59
|
-
cli.publish("/
|
60
|
-
cli.publish("/
|
55
|
+
cli.publish("/foo/tutu", "It's me!", false, 2)
|
56
|
+
cli.publish("/foo/tutu", "It's you!", false, 1)
|
57
|
+
cli.publish("/foo/tutu", "It's them!", false, 0)
|
61
58
|
|
62
|
-
cli.publish("/
|
63
|
-
cli.publish("/
|
64
|
-
cli.publish("/
|
59
|
+
cli.publish("/foo/bar", "It's me!", false, 2)
|
60
|
+
cli.publish("/foo/bar", "It's you!", false, 1)
|
61
|
+
cli.publish("/foo/bar", "It's them!", false, 0)
|
65
62
|
|
66
63
|
sleep cli.ack_timeout
|
67
64
|
|
68
|
-
cli.unsubscribe(
|
65
|
+
cli.unsubscribe("+/tutu", "+/+")
|
69
66
|
|
70
67
|
puts "Waiting 10 sec for keeping alive..."
|
71
68
|
sleep 10
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paho-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Goudet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,8 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.7
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: A simple mqtt client gem
|
125
125
|
test_files: []
|
126
|
+
has_rdoc:
|