Package mq

Functions

mq:bind

Bind a function to MQTT topic(s).

Parameters

NameOptionalDescription
TopicNoTopic pattern to bind function to
FunctionNoFunction to execute on new messages

Example

function doSomething(topic, payload, retained)
    print("Topic: " .. topic)
end

mq:bind("obj/example/+/value", doSomething)
mq:sub("obj/#", 2)

mq:sub

Create a subscription to the MQTT Broker.

Parameters

NameOptionalDescription
TopicNoTopic pattern for subscription on MQTT
QoSNoQoS of the subscription

Example

mq:sub("obj/#", 2)

mq:pub

Parameters

NameOptionalDescription
TopicNoTopic to send message to
PayloadnoData to send
RetainYesSet to true to retain messages on the broker (should be avoided). Defaults to false
QoSYesQoS level for message. Defaults to 0

Example

local payload = json:encode({value = 3.34, timestamp = edge:time() })
mq:pub("obj/example/1/value", payload, false, 0)