MqttWildcardSubscription

Description

The MqttWildcardSubscription object subscribes to an MQTT wildcard topic specified in the name property and provides the received data in the data property. The names of all received topics are available in the topics property.

The parent object must be of type MqttClient.

This object was introduced in InCore 2.3.

› Inherits:MqttAbstractSubscription

Properties

data

This property holds a map with the data of all topics matching the wildcard topic name.

› Type:Map
› Signal:dataChanged()
› Attributes:Readonly

dataType

This property holds the data type which to convert the payload of incoming messages automatically. If not specified, the payload will not be converted and inserted as raw data in the data map or passed as raw data to the valueReceived() signal.

This property was introduced in InCore 2.4.

› Type:DataObject.DataType
› Default:DataObject.Invalid
› Signal:dataTypeChanged()
› Attributes:Writable

mode

This property holds the mode which specifies how to process incoming messages. See the MqttWildcardSubscription.Mode enumeration for details.

› Type:Mode
› Default:MqttWildcardSubscription.UpdateDataMap
› Signal:modeChanged()
› Attributes:Writable

name

This property holds the name of the wildcard topic to subscribe.

› Type:String
› Signal:nameChanged()
› Attributes:Writable

topics

This property holds a list of names with all received topics matching the wildcard topic name.

› Type:StringList
› Signal:topicsChanged()
› Attributes:Readonly

Signals

valueReceived(String topicName, Variant value)

This signal is emitted whenever a new value has been received and mode is set to MqttWildcardSubscription.ReceiveValues. The name of the topic and the actual value are passed.

This signal was introduced in InCore 2.4.

Enumerations

Mode

This enumeration describes all supported modes for processing incoming messages

This enumeration was introduced in InCore 2.4.

Name Value Description
MqttWildcardSubscription.UpdateDataMap 0 Update the data map property. Use bindings to individual subproperties of the data property to use the actual data or react to xxxChanged() signals (see example).
MqttWildcardSubscription.ReceiveValues 1 Emits the valueReceived() signal on every incoming message. In this mode, the data map is not updated which can improve performance if you only need to process incoming (possibly converted) data value directly anyway.

Example

import InCore.Foundation 2.5
import InCore.Mqtt 2.5

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

        MqttWildcardSubscription {
            id: allTopics
            name: "#"
            onTopicsChanged: console.log("Names of all published topics:", topics)
            property var counter: topics.includes("incore/foo/counter") ? parseInt(data.incore.foo.counter) : 0
            onCounterChanged: console.log("Counter:", counter)
        }
        MqttWildcardSubscription {
            name: "incore/+/date"
            dataType: MqttTopic.DateTime
            mode: MqttWildcardSubscription.ReceiveValues
            onValueReceived: console.log("Date:", value)
        }

        MqttWildcardSubscription {
            id: measurements
            dataType: MqttTopic.Float
            name: "measurements/#"
        }
    }

    ObjectArray {
        Repeater on objects {
            model: measurements.topics
            Measurement {
                objectId: modelData
                data: measurements.data[modelData]
                onDataChanged: console.log("Measurement value:", objectId, data)
            }
        }
    }
}