Method: MQTT::Client#subscribe

Defined in:
lib/mqtt/client.rb

#subscribe(*topics) ⇒ Object

Send a subscribe message for one or more topics on the MQTT server. The topics parameter should be one of the following:

  • String: subscribe to one topic with QoS 0

  • Array: subscribe to multiple topics with QoS 0

  • Hash: subscribe to multiple topics where the key is the topic and the value is the QoS level

For example:

client.subscribe( 'a/b' )
client.subscribe( 'a/b', 'c/d' )
client.subscribe( ['a/b',0], ['c/d',1] )
client.subscribe( 'a/b' => 0, 'c/d' => 1 )

383
384
385
386
387
388
389
# File 'lib/mqtt/client.rb', line 383

def subscribe(*topics)
  packet = MQTT::Packet::Subscribe.new(
    :id => next_packet_id,
    :topics => topics
  )
  send_packet(packet)
end