class MQTT::V3::Client

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.cr

Constructors

Class Method Summary

Instance Method Summary

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

def self.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


[View source]
def self.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

[View source]

Class Method Detail

def self.topic_matches(filter : String, topic : String) #

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


[View source]

Instance Method Detail

def 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) #

[View source]
def disconnect(send_msg = true) : Nil #

[View source]
def parse_message(io) #
Description copied from class MQTT::ClientBase

Handles a decoded packet. Implemented per protocol version


[View source]
def ping(timeout : Time::Span | Nil = @timeout) : Nil #

Sends a PINGREQ and waits for the broker's PINGRESP


[View source]
def publish(topic : String, payload = "", retain : Bool = false, qos : QoS = QoS::FireAndForget, timeout : Time::Span | Nil = @timeout) #

[View source]
def publish_received(pub) #

[View source]
def subscribe(topics : Hash(String, Tuple(QoS, Callback)), timeout : Time::Span | Nil = @timeout) #

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


[View source]
def 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


[View source]
def subscriptions : Hash(String, QoS) #

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


[View source]
def 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


[View source]
def unsubscribe(*topics, timeout : Time::Span | Nil = @timeout) #

[View source]