Method: MQTT::Client#get
- Defined in:
- lib/mqtt/client.rb
#get(topic = nil, options = {}) ⇒ Object
Return the next message received from the MQTT server. An optional topic can be given to subscribe to.
The method either returns the topic and message as an array:
topic, = client.get
Or can be used with a block to keep processing messages:
client.get('test') do |topic,payload|
# Do stuff here
end
389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/mqtt/client.rb', line 389 def get(topic = nil, = {}) if block_given? get_packet(topic) do |packet| yield(packet.topic, packet.payload) unless packet.retain && [:omit_retained] end else loop do # Wait for one packet to be available packet = get_packet(topic) return packet.topic, packet.payload unless packet.retain && [:omit_retained] end end end |