IoT Open Tech
Home
  • Platform
  • Modules
  • Devices
Guides
Changelog
Home
  • Platform
  • Modules
  • Devices
Guides
Changelog
  • Platform

    • IoT Open Lynx Platform
    • Lynx Architecture
    • Main objects
    • DeviceX / FunctionX
      • Function types and metadata
    • Metadata
      • Known meta-keys
    • Icons
    • Schedules
    • Edge Apps
      • The app.json file
      • Package edge.lynx
      • Package edge.timer
      • Package json
      • Package mq
      • Package log
      • Package edge
    • Edge Client
      • Docker Edge Client
      • Linux Edge Client
    • Notifications
      • Templating language
      • Executors
    • Events
    • Permissions
    • API Reference and Libraries

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

-- call "doSomething" when a message arrives on topic "obj/example/+/value"
mq:bind("obj/example/+/value", doSomething)
-- subscribe to topic "obj/#" with qos 2
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

Publish a message to an MQTT topic.

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)
Last updated:
Prev
Package json
Next
Package log