mqtt-rails 1.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: '07387e175ea1e3133f15fb9bce534aab019799ebb6472bbe7d48479cb67b9405'
4
- data.tar.gz: '0438ddc874e70a232032e23a461081e798d4528191fb821523abd8f5d9a586fb'
3
+ metadata.gz: 7d42bae3dac21cb4e7667e5595f569d7b747904e64a9afb5355063d392b9743d
4
+ data.tar.gz: a8e8d27717146552022024cf378a914e6d86c22687018373d779533dab72efae
5
5
  SHA512:
6
- metadata.gz: d83640e2f6fff6190fe3ab6232d1ab2fc6a6401c4d05cadb17cc6ad9304ea40cf7d80911ae018ddc749cba5436d8566d4278fe755651bd6d239dba6b2eaf44e3
7
- data.tar.gz: f70787d2ebfa9bb889c7ec8b50103cc0b429e6cf1b736c9aee3290e6d0b0786e96d448cf8fa59896466051915f4ae32f72ee69614d0118dca73c2e9f0a862fd9
6
+ metadata.gz: 489468202873f5c0b78489a457b665e8eb0e0c72a33d46c6d3226120a3d95ba4b488ea69dfeff33765875f4d50bbc94a7b5e4b14417caf02aee3a6c7fe9a1887
7
+ data.tar.gz: 796b487d836396bca8d49518f496d356561d42382a204a4832710eaa670f9c63e702878c76d4362041bd7cf9e70ee3801fb22d94745bad2e436eaad864dd271b
@@ -137,7 +137,7 @@ module MqttRails
137
137
  def check_topics(topics, filters)
138
138
  if topics.is_a?(String) && filters.is_a?(String)
139
139
  else
140
- Rails.logger.error("Topics or Wildcards are not found as String.")
140
+ Rails.logger.error("[MQTT RAILS][ERROR] Topics or Wildcards are not found as String.")
141
141
  raise ArgumentError
142
142
  end
143
143
  end
@@ -169,7 +169,7 @@ module MqttRails
169
169
  break if result.nil?
170
170
  end
171
171
  rescue FullQueueException
172
- Rails.logger.warn("Early exit in reading loop. The maximum packets have been reach for #{packet.type_name}")
172
+ Rails.logger.warn("[MQTT RAILS][WARNING] Early exit in reading loop. The maximum packets have been reach for #{packet.type_name}")
173
173
  rescue ReadingException
174
174
  if check_persistence
175
175
  reconnect
@@ -199,7 +199,7 @@ module MqttRails
199
199
  counter = 0
200
200
  while (@reconnect_limit >= counter || @reconnect_limit == -1) do
201
201
  counter += 1
202
- Rails.logger.info("New reconnect attempt...")
202
+ Rails.logger.info("[MQTT RAILS][INFO] New reconnect attempt...")
203
203
  connect
204
204
  if connected?
205
205
  break
@@ -208,7 +208,7 @@ module MqttRails
208
208
  end
209
209
  end
210
210
  unless connected?
211
- Rails.logger.error("Reconnection attempt counter is over. (#{@reconnect_limit} times)")
211
+ Rails.logger.error("[MQTT RAILS][ERROR] Reconnection attempt counter is over. (#{@reconnect_limit} times)")
212
212
  disconnect(false)
213
213
  end
214
214
  end
@@ -228,7 +228,7 @@ module MqttRails
228
228
 
229
229
  def publish(topic, payload="", retain=false, qos=0)
230
230
  if topic == "" || !topic.is_a?(String)
231
- Rails.logger.error("Publish topics is invalid, not a string or empty.")
231
+ Rails.logger.error("[MQTT RAILS][ERROR] Publish topics is invalid, not a string or empty.")
232
232
  raise ArgumentError
233
233
  end
234
234
  id = next_packet_id
@@ -243,7 +243,7 @@ module MqttRails
243
243
  end
244
244
  MQTT_ERR_SUCCESS
245
245
  rescue ProtocolViolation
246
- Rails.logger.error("Subscribe topics need one topic or a list of topics.")
246
+ Rails.logger.error("[MQTT RAILS][ERROR] Subscribe topics need one topic or a list of topics.")
247
247
  raise ProtocolViolation
248
248
  end
249
249
  end
@@ -256,7 +256,7 @@ module MqttRails
256
256
  end
257
257
  MQTT_ERR_SUCCESS
258
258
  rescue ProtocolViolation
259
- Rails.logger.error("Unsubscribe need at least one topic.")
259
+ Rails.logger.error("[MQTT RAILS][ERROR] Unsubscribe need at least one topic.")
260
260
  raise ProtocolViolation
261
261
  end
262
262
  end
@@ -364,7 +364,7 @@ module MqttRails
364
364
  end
365
365
 
366
366
  def downgrade_version
367
- Rails.logger.info("Connection refused: unacceptable protocol version #{@mqtt_version}, trying 3.1")
367
+ Rails.logger.info("[MQTT RAILS][INFO] Connection refused: unacceptable protocol version #{@mqtt_version}, trying 3.1")
368
368
  if @mqtt_version != "3.1"
369
369
  @mqtt_version = "3.1"
370
370
  connect(@host, @port, @keep_alive)
@@ -43,7 +43,7 @@ module MqttRails
43
43
  @cs = @handler.receive_packet
44
44
  end
45
45
  unless is_connected?
46
- Rails.logger.warn("Connection failed. Couldn't recieve a Connack packet from: #{@host}.")
46
+ Rails.logger.error("[MQTT RAILS][ERROR] Connection failed. Couldn't recieve a Connack packet from: #{@host}.")
47
47
  raise Exception.new("Connection failed. Check log for more details.") unless reconnection
48
48
  end
49
49
  @cs
@@ -54,7 +54,7 @@ module MqttRails
54
54
  end
55
55
 
56
56
  def do_disconnect(publisher, explicit, mqtt_thread)
57
- Rails.logger.info("Disconnecting from #{@host}.")
57
+ Rails.logger.info("[MQTT RAILS][INFO] Disconnecting from #{@host}.")
58
58
  if explicit
59
59
  explicit_disconnect(publisher, mqtt_thread)
60
60
  end
@@ -78,7 +78,7 @@ module MqttRails
78
78
  end
79
79
 
80
80
  def config_socket
81
- Rails.logger.info("Attempt to connect to host: #{@host}...")
81
+ Rails.logger.info("[MQTT RAILS][INFO] Attempt to connect to host: #{@host}...")
82
82
  begin
83
83
  tcp_socket = TCPSocket.new(@host, @port)
84
84
  if @ssl
@@ -87,7 +87,7 @@ module MqttRails
87
87
  @socket = tcp_socket
88
88
  end
89
89
  rescue StandardError
90
- Rails.logger.warn("Could not open a socket with #{@host} on port #{@port}.")
90
+ Rails.logger.warn("[MQTT RAILS][WARNING] Could not open a socket with #{@host} on port #{@port}.")
91
91
  end
92
92
  end
93
93
 
@@ -97,7 +97,7 @@ module MqttRails
97
97
  @socket.sync_close = true
98
98
  @socket.connect
99
99
  else
100
- Rails.logger.error("The SSL context was found as nil while the socket's opening.")
100
+ Rails.logger.error("[MQTT RAILS][ERROR] The SSL context was found as nil while the socket's opening.")
101
101
  raise Exception
102
102
  end
103
103
  end
@@ -113,7 +113,7 @@ module MqttRails
113
113
 
114
114
  def host=(host)
115
115
  if host.nil? || host == ""
116
- Rails.logger.error("The host was found as nil while the connection setup.")
116
+ Rails.logger.error("[MQTT RAILS][ERROR] The host was found as nil while the connection setup.")
117
117
  raise ArgumentError
118
118
  else
119
119
  @host = host
@@ -122,7 +122,7 @@ module MqttRails
122
122
 
123
123
  def port=(port)
124
124
  if port.to_i <= 0
125
- Rails.logger.error("The port value is invalid (<= 0). Could not setup the connection.")
125
+ Rails.logger.error("[MQTT RAILS][ERROR] The port value is invalid (<= 0). Could not setup the connection.")
126
126
  raise ArgumentError
127
127
  else
128
128
  @port = port
@@ -158,12 +158,12 @@ module MqttRails
158
158
  last_packet_received_at = @handler.last_packet_received_at
159
159
  # send a PINGREQ only if we don't already wait for a PINGRESP
160
160
  if persistent && should_send_ping?(now, keep_alive, last_packet_received_at)
161
- Rails.logger.info("Checking if server is still alive...")
161
+ Rails.logger.info("[MQTT RAILS][INFO] Checking if server is still alive...")
162
162
  @sender.send_pingreq
163
163
  end
164
164
  disconnect_timeout_at = last_packet_received_at + (keep_alive * 1.1).ceil
165
165
  if disconnect_timeout_at <= now
166
- Rails.logger.info("No activity is over timeout, disconnecting from #{@host}.")
166
+ Rails.logger.info("[MQTT RAILS][INFO] No activity is over timeout, disconnecting from #{@host}.")
167
167
  @cs = MQTT_CS_DISCONNECT
168
168
  end
169
169
  @cs
@@ -52,14 +52,14 @@ module MqttRails
52
52
  end
53
53
 
54
54
  def handle_packet(packet)
55
- Rails.logger.info("New packet #{packet.class} received.")
55
+ Rails.logger.info("[MQTT RAILS][INFO] New packet #{packet.class} received.")
56
56
  type = packet_type(packet)
57
57
  self.send("handle_#{type}", packet)
58
58
  end
59
59
 
60
60
  def register_topic_callback(topic, callback, &block)
61
61
  if topic.nil?
62
- Rails.logger.error("The topics where the callback is trying to be registered have been found nil.")
62
+ Rails.logger.error("[MQTT RAILS][ERROR] The topics where the callback is trying to be registered have been found nil.")
63
63
  raise ArgumentError
64
64
  end
65
65
  clear_topic_callback(topic)
@@ -73,7 +73,7 @@ module MqttRails
73
73
 
74
74
  def clear_topic_callback(topic)
75
75
  if topic.nil?
76
- Rails.logger.error("The topics where the callback is trying to be unregistered have been found nil.")
76
+ Rails.logger.error("[MQTT RAILS][ERROR] The topics where the callback is trying to be unregistered have been found nil.")
77
77
  raise ArgumentError
78
78
  end
79
79
  @registered_callback.delete_if { |pair| pair.first == topic }
@@ -101,19 +101,19 @@ module MqttRails
101
101
 
102
102
  def new_session?(session_flag)
103
103
  if !@clean_session && !session_flag
104
- Rails.logger.info("New session created for the client.")
104
+ Rails.logger.info("[MQTT RAILS][INFO] New session created for the client.")
105
105
  end
106
106
  end
107
107
 
108
108
  def clean_session?(session_flag)
109
109
  if @clean_session && !session_flag
110
- Rails.logger.info("No previous session found by server, starting a new one.")
110
+ Rails.logger.info("[MQTT RAILS][INFO] No previous session found by server, starting a new one.")
111
111
  end
112
112
  end
113
113
 
114
114
  def old_session?(session_flag)
115
115
  if !@clean_session && session_flag
116
- Rails.logger.info("Previous session restored by the server.")
116
+ Rails.logger.info("[MQTT RAILS][INFO] Previous session restored by the server.")
117
117
  end
118
118
  end
119
119
 
@@ -254,7 +254,7 @@ module MqttRails
254
254
  if MqttRails::PACKET_TYPES[3..13].include?(type)
255
255
  type.to_s.split('::').last.downcase
256
256
  else
257
- Rails.logger.error("Received an unexpeceted packet: #{packet}.")
257
+ Rails.logger.error("[MQTT RAILS][ERROR] Received an unexpeceted packet: #{packet}.")
258
258
  raise PacketException.new('Invalid packet type id')
259
259
  end
260
260
  end
@@ -47,7 +47,7 @@ module MqttRails
47
47
  push_queue(@waiting_pubrec, @pubrec_mutex, MAX_QUEUE, packet, new_id)
48
48
  end
49
49
  rescue FullQueueException
50
- Rails.logger.warn("PUBLISH queue is full, waiting for publishing #{packet.inspect}")
50
+ Rails.logger.warn("[MQTT RAILS][WARNING] PUBLISH queue is full, waiting for publishing #{packet.inspect}")
51
51
  sleep SELECT_TIMEOUT
52
52
  retry
53
53
  end
@@ -73,7 +73,7 @@ module MqttRails
73
73
  when 2
74
74
  send_pubrec(packet_id)
75
75
  else
76
- Rails.logger.error("The packet QoS value is invalid in publish.")
76
+ Rails.logger.error("[MQTT RAILS][ERROR] The packet QoS value is invalid in publish.")
77
77
  raise PacketException.new('Invalid publish QoS value')
78
78
  end
79
79
  MQTT_ERR_SUCCESS
@@ -58,7 +58,7 @@ module MqttRails
58
58
  queue.push(packet)
59
59
  end
60
60
  else
61
- Rails.logger.error('Writing queue is full, slowing down')
61
+ Rails.logger.error('[MQTT RAILS][ERROR] Writing queue is full, slowing down')
62
62
  raise FullWritingException
63
63
  end
64
64
  end
@@ -118,7 +118,7 @@ module MqttRails
118
118
  queue.each do |pck|
119
119
  if now >= pck[:timestamp] + @ack_timeout
120
120
  pck[:packet].dup ||= true unless pck[:packet].class == MqttRails::Packet::Subscribe || pck[:packet].class == MqttRails::Packet::Unsubscribe
121
- Rails.logger.info("Acknowledgement timeout is over, resending #{pck[:packet].inspect}")
121
+ Rails.logger.info("[MQTT RAILS][INFO] Acknowledgement timeout is over, resending #{pck[:packet].inspect}")
122
122
  send_packet(pck[:packet])
123
123
  pck[:timestamp] = now
124
124
  end
@@ -42,7 +42,7 @@ module MqttRails
42
42
  end
43
43
  @suback_mutex.synchronize do
44
44
  if @waiting_suback.length >= MAX_SUBACK
45
- Rails.logger.error('SUBACK queue is full, could not send subscribe')
45
+ Rails.logger.error('[MQTT RAILS][ERROR] SUBACK queue is full, could not send subscribe')
46
46
  return MQTT_ERR_FAILURE
47
47
  end
48
48
  @waiting_suback.push(:id => new_id, :packet => packet, :timestamp => Time.now)
@@ -64,12 +64,12 @@ module MqttRails
64
64
  elsif max_qos[0] == 128
65
65
  adjust_qos.delete(t)
66
66
  else
67
- Rails.logger.error("The QoS value is invalid in subscribe.")
67
+ Rails.logger.error("[MQTT RAILS][ERROR] The QoS value is invalid in subscribe.")
68
68
  raise PacketException.new('Invalid suback QoS value')
69
69
  end
70
70
  end
71
71
  else
72
- Rails.logger.error("The packet id is invalid, already used.")
72
+ Rails.logger.error("[MQTT RAILS][ERROR] The packet id is invalid, already used.")
73
73
  raise PacketException.new("Invalid suback packet id: #{packet_id}")
74
74
  end
75
75
  @subscribed_mutex.synchronize do
@@ -86,7 +86,7 @@ module MqttRails
86
86
  if to_unsub.length == 1
87
87
  to_unsub = to_unsub.first[:packet].topics
88
88
  else
89
- Rails.logger.error("The packet id is invalid, already used.")
89
+ Rails.logger.error("[MQTT RAILS][ERROR] The packet id is invalid, already used.")
90
90
  raise PacketException.new("Invalid unsuback packet id: #{packet_id}")
91
91
  end
92
92
 
@@ -107,7 +107,7 @@ module MqttRails
107
107
  @sender.append_to_writing(packet)
108
108
  @suback_mutex.synchronize do
109
109
  if @waiting_suback.length >= MAX_SUBACK
110
- Rails.logger.error('SUBACK queue is full, could not send subscribe')
110
+ Rails.logger.error('[MQTT RAILS][ERROR] SUBACK queue is full, could not send subscribe')
111
111
  return MQTT_ERR_FAILURE
112
112
  end
113
113
  @waiting_suback.push(:id => new_id, :packet => packet, :timestamp => Time.now)
@@ -127,7 +127,7 @@ module MqttRails
127
127
  @sender.append_to_writing(packet)
128
128
  @unsuback_mutex.synchronize do
129
129
  if @waiting_suback.length >= MAX_UNSUBACK
130
- Rails.logger.error('UNSUBACK queue is full, could not send unbsubscribe')
130
+ Rails.logger.error('[MQTT RAILS][ERROR] UNSUBACK queue is full, could not send unbsubscribe')
131
131
  return MQTT_ERR_FAIL
132
132
  end
133
133
  @waiting_unsuback.push(:id => new_id, :packet => packet, :timestamp => Time.now)
@@ -1,3 +1,3 @@
1
1
  module MqttRails
2
- VERSION = "1.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,7 +1,5 @@
1
1
  require 'mqtt-rails'
2
2
 
3
- Rails.logger = ('mqtt_rails.log')
4
-
5
3
  client = MqttRails::Client.new()
6
4
 
7
5
  client.on_message = lambda { |p| puts ">>>>> This is the callback for a message event <<<<<\nTopic: #{p.topic}\nPayload: #{p.payload}\nQoS: #{p.qos}" }
@@ -2,7 +2,6 @@ require 'mqtt-rails'
2
2
 
3
3
  ### Create a simple client with default attributes
4
4
  client = MqttRails::Client.new
5
- Rails.logger = 'mqtt_rails'
6
5
  ### Register a callback on message event to display messages
7
6
  message_counter = 0
8
7
  client.on_message do |message|
@@ -1,7 +1,6 @@
1
1
  require "mqtt-rails"
2
2
 
3
3
  cli = MqttRails::Client.new({persistent: true, keep_alive: 7})
4
- Rails.logger = 'paho_log'
5
4
 
6
5
  cli.connect('localhost', 1883)
7
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas KOVACS