# Package mq

# Functions

# mq:bind

Bind a function to MQTT topic(s).

# Parameters

Name Optional Description
Topic No Topic pattern to bind function to
Function No Function 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

Name Optional Description
Topic No Topic pattern for subscription on MQTT
QoS No QoS of the subscription

# Example

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

# mq:pub

# Parameters

Name Optional Description
Topic No Topic to send message to
Payload no Data to send
Retain Yes Set to true to retain messages on the broker (should be avoided). Defaults to false
QoS Yes QoS 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)