MQTT.QOSType
QOS

An enum representing the different Quality of Service (QoS) levels in MQTT.

Values

  • AT_MOST_ONCE: QoS level 0, at most once delivery. The message is delivered at most once, or it may not be delivered at all. This is also known as "fire and forget".
  • AT_LEAST_ONCE: QoS level 1, at least once delivery. The message is guaranteed to be delivered at least once, but it may be delivered multiple times.
  • EXACTLY_ONCE: QoS level 2, exactly once delivery. The message is guaranteed to be delivered exactly once.
source
MQTT.MQTTConnectionFunction
MQTTConnection()

This function constructs the connection struct that a given backend needs for interfacing with the MQTT Broker.

source
MQTT.connect_async!Function
connect_async!(c::AbstractConnection)

Make a connection to a broker.

Returns immediately, does not wait for an acknowledgement.

source
MQTT.connect!Function
connect!(c::AbstractConnection)

Connect to a broker and wait for the connection to be acknowledged.

Example

mqttconnection = ...
connect!(mqttconnection)
source
MQTT.subscribe_async!Function
subscribe_async!(callback::OnMessage, connection::AbstractConnection, topic, qos::QOS)

Subscribe to a topic.

Returns immediately, does not wait for acknowledgement.

source
MQTT.subscribe!Function
subscribe!(callback::OnMessage, connection::AbstractConnection, topic, qos::QOS)

Subscribe to a topic and wait for subscription to be acknowledged.

Example

Either use a previously defined callback function cb:

cb(topic, payload) = do_a_thing_for_device_one(payload)
subscribe!(cb, mqttconnection, "group1/device1", QOS.EXACTLY_ONCE)

Or define the callback in a do block:

subscribe!(mqttconnection, "group1/device2", QOS.EXACTLY_ONCE) do topic, payload
    do_a_thing_for_device_two(payload)
end

The code in your function may be executed in a different thread than the main application! It is recommended to use asynchronous function calls inside of the callback. For example, use subscribe_async! inside of callbacks instead of the blocking subscribe! version.

source
MQTT.publish_async!Function
publish_async!(connection::AbstractConnection, topic, payload, qos::QOS; retain = false)

Publish to a topic.

Returns immediately, does not wait for acknowledgment.

source
MQTT.publish!Function
publish!(connection::AbstractConnection, topic, payload, qos::QOS; retain = false)

Publish to a topic and wait for message to be acknowledged.

Example

publish!(mqttconnection, "group1/device1", "hello world", QOS.EXACTLY_ONCE)
source
MQTT.unsubscribe_async!Function
unsubscribe_async!(connection::AbstractConnection, topic)

Unsubscribe from a topic.

Returns immediately, does not wait for acknowledgement.

source
MQTT.unsubscribe!Function
unsubscribe!(connection::AbstractConnection, topic)

Unsubscribe from a topic and wait for unsubscription to be acknowledged.

Example

unsubscribe!(mqttconnection, "group1/device1")
source
MQTT.disconnect!Function
disconnect!(connection::AbstractConnection)

Disconnect from a broker, and wait for disconnect to be acknowledged.

Example

disconnect!(mqttconnection)
source