class

MQTT::V3::Client

Inherits MQTT::ClientBase / Reference / Object

https://test.mosquitto.org/

The transport lifecycle, request pipeline, keep alive and reconnection all live in MQTT::ClientBase. What follows is the 3.1.1 specific half: building packets, parsing them, and what an acknowledgement means

Constructors

new(transport : Transport, timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE)

Drives the client over a single transport. The connection is not retried if it drops, see the block form for that

Source
new(timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE, reconnect : MQTT::Reconnect = MQTT::Reconnect.new, &factory : -> Transport)

Drives the client over transports produced by the block, re-establishing the connection (and its subscriptions) whenever it drops.

client = MQTT::V3::Client.new(reconnect: MQTT::Reconnect.new) do
  MQTT::Transport::TCP.new("test.mosquitto.org")
end
client.connect
Source

Class methods

topic_matches(filter : String, topic : String)

Based on https://github.com/ralphtheninja/mqtt-match/blob/master/index.js

Source

Instance methods

connect(username : String | Nil = nil, password : String | Nil = nil, keep_alive : Int32 = 60, client_id : String = MQTT.generate_client_id, clean_start : Bool = true, will_flag : Bool = false, will_qos : Int32 | QoS = 0, will_retain : Bool = false, will_topic : String | Nil = nil, will_payload : String | Bytes | Nil = nil, timeout : Time::Span | Nil = @timeout, keep_alive_active : Bool = true)
Source
disconnect(send_msg = true) : Nil
Source
parse_message(io)

Handles a decoded packet. Implemented per protocol version

Source
ping(timeout : Time::Span | Nil = @timeout) : Nil

Sends a PINGREQ and waits for the broker's PINGRESP

Source
publish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout)
Source
publish_received(pub)
Source
subscribe(topics : Hash(String, Tuple(QoS, Callback)), timeout : Time::Span | Nil = @timeout)

http://www.steves-internet-guide.com/understanding-mqtt-topics/

Source
subscribe(*topics, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout, &callback : String, Bytes, Bool -> Nil)

NOTE:: the block may take two parameters (topic, payload) or three (topic, payload, retained). Crystal lets a shorter block satisfy the longer restriction, so existing two parameter blocks are unaffected

Source
subscriptions

The QoS the broker granted for each active subscription. A broker is free to downgrade the level you asked for, so this is not necessarily what was requested

Source
unsubscribe(topic : String, callback : Callback, timeout : Time::Span | Nil = @timeout)

Removes a single callback, only unsubscribing once the last callback for the filter has been removed

Source
unsubscribe(*topics, timeout : Time::Span | Nil = @timeout)
Source

Nested types