Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/mqtt/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Client
# Port number of the remote server
attr_accessor :port

# The version number of the MQTT protocol to use (default 3.1.1)
# The version number of the MQTT protocol to use (default 5.0)
attr_accessor :version

# Set to true to enable SSL/TLS encrypted communication
Expand Down Expand Up @@ -69,7 +69,7 @@ class Client
ATTR_DEFAULTS = {
:host => nil,
:port => nil,
:version => '3.1.1',
:version => '5.0',
:keep_alive => 15,
:clean_session => true,
:client_id => nil,
Expand Down Expand Up @@ -309,7 +309,7 @@ def disconnect(send_msg = true)

# Close the socket if it is open
if send_msg
packet = MQTT::Packet::Disconnect.new
packet = MQTT::Packet::Disconnect.new(:version => @version)
send_packet(packet)
end
@socket.close unless @socket.nil?
Expand All @@ -328,6 +328,7 @@ def publish(topic, payload = '', retain = false, qos = 0)
raise ArgumentError, 'Topic name cannot be empty' if topic.empty?

packet = MQTT::Packet::Publish.new(
:version => @version,
:id => next_packet_id,
:qos => qos,
:retain => retain,
Expand Down Expand Up @@ -375,6 +376,7 @@ def publish(topic, payload = '', retain = false, qos = 0)
#
def subscribe(*topics)
packet = MQTT::Packet::Subscribe.new(
:version => @version,
:id => next_packet_id,
:topics => topics
)
Expand Down Expand Up @@ -458,6 +460,7 @@ def unsubscribe(*topics)
topics = topics.first if topics.is_a?(Enumerable) && topics.count == 1

packet = MQTT::Packet::Unsubscribe.new(
:version => @version,
:topics => topics,
:id => next_packet_id
)
Expand All @@ -474,7 +477,7 @@ def receive_packet
handle_timeouts
unless result.nil?
# Yes - read in the packet
packet = MQTT::Packet.read(@socket)
packet = MQTT::Packet.read(@socket, version: @version)
handle_packet packet
end
keep_alive!
Expand Down
Loading