MQTT.QOS
MQTT.MQTTConnection
MQTT.connect!
MQTT.connect_async!
MQTT.disconnect!
MQTT.disconnect_async!
MQTT.publish!
MQTT.publish_async!
MQTT.subscribe!
MQTT.subscribe_async!
MQTT.unsubscribe!
MQTT.unsubscribe_async!
MQTT.QOS
— TypeQOS
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.
MQTT.MQTTConnection
— FunctionMQTTConnection()
This function constructs the connection struct that a given backend needs for interfacing with the MQTT Broker.
MQTT.connect_async!
— Functionconnect_async!(c::AbstractConnection)
Make a connection to a broker.
Returns immediately, does not wait for an acknowledgement.
MQTT.connect!
— Functionconnect!(c::AbstractConnection)
Connect to a broker and wait for the connection to be acknowledged.
Example
mqttconnection = ...
connect!(mqttconnection)
MQTT.subscribe_async!
— Functionsubscribe_async!(callback::OnMessage, connection::AbstractConnection, topic, qos::QOS)
Subscribe to a topic.
Returns immediately, does not wait for acknowledgement.
MQTT.subscribe!
— Functionsubscribe!(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.
MQTT.publish_async!
— Functionpublish_async!(connection::AbstractConnection, topic, payload, qos::QOS; retain = false)
Publish to a topic.
Returns immediately, does not wait for acknowledgment.
MQTT.publish!
— Functionpublish!(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)
MQTT.unsubscribe_async!
— Functionunsubscribe_async!(connection::AbstractConnection, topic)
Unsubscribe from a topic.
Returns immediately, does not wait for acknowledgement.
MQTT.unsubscribe!
— Functionunsubscribe!(connection::AbstractConnection, topic)
Unsubscribe from a topic and wait for unsubscription to be acknowledged.
Example
unsubscribe!(mqttconnection, "group1/device1")
MQTT.disconnect_async!
— Functiondisconnect_async!(connection::AbstractConnection)
Disconnect from a broker.
MQTT.disconnect!
— Functiondisconnect!(connection::AbstractConnection)
Disconnect from a broker, and wait for disconnect to be acknowledged.
Example
disconnect!(mqttconnection)