class
MQTT::V3::Client
- MQTT::V3::Client
- MQTT::ClientBase
- Reference
- Object
Overview
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
Defined in:
mqtt/v3/client.crConstructors
-
.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.
-
.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.
Class Method Summary
-
.topic_matches(filter : String, topic : String)
Based on https://github.com/ralphtheninja/mqtt-match/blob/master/index.js
Instance Method Summary
- #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)
- #disconnect(send_msg = true) : Nil
-
#parse_message(io)
Handles a decoded packet.
-
#ping(timeout : Time::Span | Nil = @timeout) : Nil
Sends a PINGREQ and waits for the broker's PINGRESP
- #publish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout)
- #publish_received(pub)
-
#subscribe(topics : Hash(String, Tuple(QoS, Callback)), timeout : Time::Span | Nil = @timeout)
http://www.steves-internet-guide.com/understanding-mqtt-topics/
-
#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).
-
#subscriptions : Hash(String, QoS)
The QoS the broker granted for each active subscription.
-
#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
- #unsubscribe(*topics, timeout : Time::Span | Nil = @timeout)
Instance methods inherited from class MQTT::ClientBase
closed?
closed?,
last_ping_response : Time | Nil
last_ping_response,
max_packet_size : UInt32
max_packet_size,
parse_message(io)
parse_message,
ping(timeout : Time::Span | Nil) : Nil
ping,
terminated? : Bool
terminated?,
timeout : Time::Span | Nil
timeout,
timeout=(timeout : Time::Span | Nil)
timeout=,
wait_close : Nil
wait_close
Constructor methods inherited from class MQTT::ClientBase
new(timeout : Time::Span | Nil, max_packet_size : UInt32, factory : Proc(Transport), reconnect : MQTT::Reconnect)new(transport : Transport, timeout : Time::Span | Nil = DEFAULT_TIMEOUT, max_packet_size : UInt32 = MQTT::DEFAULT_MAX_PACKET_SIZE) new
Constructor Detail
Drives the client over a single transport. The connection is not retried if it drops, see the block form for that
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
Class Method Detail
Based on https://github.com/ralphtheninja/mqtt-match/blob/master/index.js
Instance Method Detail
Handles a decoded packet. Implemented per protocol version
Sends a PINGREQ and waits for the broker's PINGRESP
http://www.steves-internet-guide.com/understanding-mqtt-topics/
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
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
Removes a single callback, only unsubscribing once the last callback for the filter has been removed