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
Sourcenew(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
SourceClass methods
topic_matches(filter : String, topic : String)
Based on https://github.com/ralphtheninja/mqtt-match/blob/master/index.js
SourceInstance 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)
Sourcedisconnect(send_msg = true) : Nil
Sourceparse_message(io)
Handles a decoded packet. Implemented per protocol version
Sourceping(timeout : Time::Span | Nil = @timeout) : Nil
Sends a PINGREQ and waits for the broker's PINGRESP
Sourcepublish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout)
Sourcesubscribe(topics : Hash(String, Tuple(QoS, Callback)), timeout : Time::Span | Nil = @timeout)
http://www.steves-internet-guide.com/understanding-mqtt-topics/
Sourcesubscribe(*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
Sourcesubscriptions
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
Sourceunsubscribe(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
Sourceunsubscribe(*topics, timeout : Time::Span | Nil = @timeout)
Source