.. _object_MqttWildcardSubscription: :index:`MqttWildcardSubscription` --------------------------------- Description *********** The MqttWildcardSubscription object subscribes to an MQTT wildcard topic specified in the :ref:`name ` property and provides the received data in the :ref:`data ` property. The names of all received topics are available in the :ref:`topics ` property. The parent object must be of type :ref:`MqttClient `. This object was introduced in InCore 2.3. :**› Inherits**: :ref:`MqttAbstractSubscription ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 2 * :ref:`data ` * :ref:`dataType ` * :ref:`mode ` * :ref:`name ` * :ref:`topics ` * :ref:`updateTopics ` * :ref:`MqttAbstractSubscription.autoSubscribe ` * :ref:`MqttAbstractSubscription.enabled ` * :ref:`MqttAbstractSubscription.error ` * :ref:`MqttAbstractSubscription.errorString ` * :ref:`MqttAbstractSubscription.qos ` * :ref:`MqttAbstractSubscription.subscribed ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 2 * :ref:`mapDataObject() ` * :ref:`unmapDataObject() ` * :ref:`MqttAbstractSubscription.subscribe() ` * :ref:`MqttAbstractSubscription.unsubscribe() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`valueReceived() ` * :ref:`MqttAbstractSubscription.errorOccurred() ` * :ref:`Object.completed() ` Enumerations ++++++++++++ .. hlist:: :columns: 1 * :ref:`Mode ` * :ref:`MqttAbstractSubscription.Error ` Properties ********** .. _property_MqttWildcardSubscription_data: .. _signal_MqttWildcardSubscription_dataChanged: .. index:: single: data data ++++ This property holds a map with the data of all topics matching the wildcard topic :ref:`name `. :**› Type**: Map :**› Signal**: dataChanged() :**› Attributes**: Readonly .. _property_MqttWildcardSubscription_dataType: .. _signal_MqttWildcardSubscription_dataTypeChanged: .. index:: single: dataType 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 :ref:`data ` map or passed as raw data to the :ref:`valueReceived() ` signal. This property was introduced in InCore 2.4. :**› Type**: :ref:`DataObject.DataType ` :**› Default**: :ref:`DataObject.Invalid ` :**› Signal**: dataTypeChanged() :**› Attributes**: Writable .. _property_MqttWildcardSubscription_mode: .. _signal_MqttWildcardSubscription_modeChanged: .. index:: single: mode mode ++++ This property holds the mode which specifies how to process incoming messages. See the :ref:`MqttWildcardSubscription.Mode ` enumeration for details. :**› Type**: :ref:`Mode ` :**› Default**: :ref:`MqttWildcardSubscription.UpdateDataMap ` :**› Signal**: modeChanged() :**› Attributes**: Writable .. _property_MqttWildcardSubscription_name: .. _signal_MqttWildcardSubscription_nameChanged: .. index:: single: name name ++++ This property holds the name of the wildcard topic to subscribe. :**› Type**: String :**› Signal**: nameChanged() :**› Attributes**: Writable .. _property_MqttWildcardSubscription_topics: .. _signal_MqttWildcardSubscription_topicsChanged: .. index:: single: topics topics ++++++ This property holds a list of names with all received topics matching the wildcard topic :ref:`name `. :**› Type**: StringList :**› Signal**: topicsChanged() :**› Attributes**: Readonly .. _property_MqttWildcardSubscription_updateTopics: .. _signal_MqttWildcardSubscription_updateTopicsChanged: .. index:: single: updateTopics updateTopics ++++++++++++ This property holds whether to update the :ref:`topics ` property on every incoming message. If the topic list is not required, you can set this property to ``false`` to improve performance. This property was introduced in InCore 2.7. :**› Type**: Boolean :**› Default**: ``true`` :**› Signal**: updateTopicsChanged() :**› Attributes**: Writable Methods ******* .. _method_MqttWildcardSubscription_mapDataObject: .. index:: single: mapDataObject mapDataObject(String topicName, :ref:`DataObject ` dataObject) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This method registers the given :ref:`DataObject ` instance to receive value for a certain topic name in the :ref:`DataObject.data ` property directly. This method was introduced in InCore 2.7. .. _method_MqttWildcardSubscription_unmapDataObject: .. index:: single: unmapDataObject unmapDataObject(:ref:`DataObject ` dataObject) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ This method removes the :ref:`DataObject ` registration for a certain object. This method was introduced in InCore 2.7. Signals ******* .. _signal_MqttWildcardSubscription_valueReceived: .. index:: single: valueReceived valueReceived(String topicName, Variant value) ++++++++++++++++++++++++++++++++++++++++++++++ This signal is emitted whenever a new value has been received and :ref:`mode ` is set to :ref:`MqttWildcardSubscription.ReceiveValues `. The name of the topic and the actual value are passed. This signal was introduced in InCore 2.4. Enumerations ************ .. _enum_MqttWildcardSubscription_Mode: .. index:: single: Mode Mode ++++ This enumeration describes all supported modes for processing incoming messages This enumeration was introduced in InCore 2.4. .. index:: single: MqttWildcardSubscription.UpdateDataMap .. index:: single: MqttWildcardSubscription.ReceiveValues .. index:: single: MqttWildcardSubscription.WriteToDataOfMappedDataObjects .. index:: single: MqttWildcardSubscription.WriteToTimestampOfMappedDataObjects .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_MqttWildcardSubscription_UpdateDataMap: * - ``MqttWildcardSubscription.UpdateDataMap`` - ``0`` - Update the :ref:`data ` map property. Use bindings to individual subproperties of the :ref:`data ` property to use the actual data or react to ``xxxChanged()`` signals (see example). .. _enumitem_MqttWildcardSubscription_ReceiveValues: * - ``MqttWildcardSubscription.ReceiveValues`` - ``1`` - Emits the :ref:`valueReceived() ` signal on every incoming message. In this mode, the :ref:`data ` map is not updated which can improve performance if you only need to process incoming (possibly converted) data value directly anyway. .. _enumitem_MqttWildcardSubscription_WriteToDataOfMappedDataObjects: * - ``MqttWildcardSubscription.WriteToDataOfMappedDataObjects`` - ``2`` - writes the received value to the :ref:`DataObject.data ` property of the :ref:`DataObject ` which has been associated with the respective topic name using the :ref:`mapDataObject() ` method. .. _enumitem_MqttWildcardSubscription_WriteToTimestampOfMappedDataObjects: * - ``MqttWildcardSubscription.WriteToTimestampOfMappedDataObjects`` - ``3`` - writes the received value to the :ref:`DataObject.timestamp ` property of the :ref:`DataObject ` which has been associated with the respective topic name using the :ref:`mapDataObject() ` method. .. _example_MqttWildcardSubscription: Example ******* .. code-block:: qml 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) } } } }