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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed14883e1ebd2e1498ad540c517a808d8d6c8b51
4
- data.tar.gz: 38d3f1223a5f677ea75acdba57969091a68918c5
3
+ metadata.gz: 6e96a49570aa770ba8c03e15a22b3f07dab8c537
4
+ data.tar.gz: 33be02b618285d8493528df49641583e432398df
5
5
  SHA512:
6
- metadata.gz: efd6ae4e713a3ab0fde5acbf7040028efafdd9bbccdfa2cfc66401ac2d1e636969760cbf9a5f4b0b469c389813617ddc11a1fa08a5684152130effaf227b2685
7
- data.tar.gz: '08900c8d295b3419238b8950959e34e22be9ad344e44cc8f1b95630d490812ff116a00f3160f670b9148d7715f2309e86778307e358ee658d7f75503e8e0f2a0'
6
+ metadata.gz: 19536ea5cd1d728654965db904f9fee6a204afb783979b178b835d735f947199778523c332941fec72dec1d21e6a853c5d2eb91ea45f51cf67119209a2115862
7
+ data.tar.gz: 285e5abeabd2aabdd9ccc6072da616868b311870e875cfe5cd57f22d80acf766cd9acc4ab961869f73d7fd69b75ab26b487b4def1a6b2af3280b41833aa5d82e
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ *.gem
12
+ *.log
@@ -106,7 +106,7 @@ module PahoMqtt
106
106
  file = File.open(logger_path, "a+")
107
107
  log_file = Logger.new(file)
108
108
  log_file.level = Logger::DEBUG
109
- @action_manager.logger = log_file
109
+ @logger = log_file
110
110
  end
111
111
 
112
112
  def logger
@@ -71,7 +71,6 @@ module PahoMqtt
71
71
  end
72
72
 
73
73
  if @port.nil?
74
- @port
75
74
  if @ssl
76
75
  @port = DEFAULT_SSL_PORT
77
76
  else
@@ -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.first) }
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
- return MQTT_ERR_FAIL if topic.first == ""
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
@@ -1,3 +1,3 @@
1
1
  module PahoMqtt
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -1,16 +1,18 @@
1
1
  require 'paho-mqtt'
2
- require 'logger'
3
2
 
4
- file = File.open('paho_writting.log', "a+")
5
- log = Logger.new(file)
6
- log.level = Logger::DEBUG
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
@@ -1,11 +1,8 @@
1
1
  require "paho-mqtt"
2
2
  require "logger"
3
3
 
4
- file = File.open('paho.log', "a+")
5
- log = Logger.new(file)
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
- toto_toto = lambda { puts ">>>>> I am LAMBDA callback for the /toto/toto topic <<<<<" }
20
- toto_tata = proc { puts ">>>>> I am PROC callback for the /toto/tata topic <<<<<" }
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('/toto/tutu') do
24
- puts ">>>>> I am BLOCK callback for the /toto/tutu topic <<<<<"
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('/toto/tata', toto_tata)
27
- cli.add_topic_callback('/toto/toto', toto_toto)
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(['/toto/toto', 0], ['/toto/tata', 1], ['/toto/tutu', 2], ["/toto", 0])
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("/toto/tutu", "It's me!", false, 2)
38
- cli.publish("/toto/tutu", "It's you!", false, 1)
39
- cli.publish("/toto/tutu", "It's them!", false, 0)
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("/toto/tata", "It's me!", false, 2)
42
- cli.publish("/toto/tata", "It's you!", false, 1)
43
- cli.publish("/toto/tata", "It's them!", false, 0)
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("/toto/toto", "It's me!", false, 2)
46
- cli.publish("/toto/toto", "It's you!", false, 1)
47
- cli.publish("/toto/toto", "It's them!", false, 0)
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
- toto_tutu = lambda { puts ">>>>> Changing callback type to LAMBDA for the /toto/tutu topic <<<<<" }
53
- cli.add_topic_callback('/toto/tutu', toto_tutu)
54
- cli.add_topic_callback('/toto/tata') do
55
- puts ">>>>> Changing callback type to BLOCK for the /toto/tata topic <<<<<"
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("/toto/tutu", "It's me!", false, 2)
59
- cli.publish("/toto/tutu", "It's you!", false, 1)
60
- cli.publish("/toto/tutu", "It's them!", false, 0)
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("/toto/tata", "It's me!", false, 2)
63
- cli.publish("/toto/tata", "It's you!", false, 1)
64
- cli.publish("/toto/tata", "It's them!", false, 0)
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('+/tutu', "+/+")
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.2
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-08-17 00:00:00.000000000 Z
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.4.5.1
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: