Bind a function to MQTT topic(s).
Name | Optional | Description |
---|
Topic | No | Topic pattern to bind function to |
Function | No | Function to execute on new messages |
function doSomething(topic, payload, retained)
print("Topic: " .. topic)
end
mq:bind("obj/example/+/value", doSomething)
mq:sub("obj/#", 2)
Create a subscription to the MQTT Broker.
Name | Optional | Description |
---|
Topic | No | Topic pattern for subscription on MQTT |
QoS | No | QoS of the subscription |
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 |
local payload = json:encode({value = 3.34, timestamp = edge:time() })
mq:pub("obj/example/1/value", payload, false, 0)