MqttSubscription

Description

The MqttSubscription object manages subscriptions of one or multiple MQTT topics published by another instance on the MQTT broker. Unless disabled explicitely via the MqttAbstractSubscription.autoSubscribe property all topics are subscribed automatically.

The parent object must be of type MqttClient.

› Inherits:MqttAbstractSubscription

Properties

topics

This property holds a list of MQTT topics to subscribe.

› Type:List<MqttTopic>
› Signal:topicsChanged()
› Attributes:Readonly

Signals

topicsDataChanged(SignedInteger index)

This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index in the topics list itself emitted the dataChanged() signal.

Example

import InCore.Foundation 2.5
import InCore.Mqtt 2.5

Application {
    MqttClient {
        clientId: "MqttSubscriptionExample"
        hostname: "localhost"

        MqttSubscription {
            qos: 1
            onSubscribedChanged: console.log("Subscribed to topics")

            MqttTopic {
                name: "incore/temperature"
                dataType: MqttTopic.Float
                onDataChanged: console.log("Device temperature changed to", data)
            }

            MqttTopic {
                name: "incore/foo/counter"
                onDataChanged: console.log("Counter changed to", data)
            }

            MqttTopic {
                name: "incore/bar/date"
                dataType: DataObject.DateTime
                onDataChanged: console.log("Date changed to", data)
            }

            MqttTopic {
                name: "incore/array"
                dataType: DataObject.StringList
                onDataChanged: console.log("Array data:", data)
            }

        }
    }
}