MqttAbstractSubscription

Description

The MqttAbstractSubscription object provides common properties and mechanisms for subscription objects.

› Inherits:Object
› Inherited by:MqttSubscription, MqttWildcardSubscription

Properties

autoSubscribe

This property holds whether to subscribe the topics automatically whenever the associated MqttClient successfully established a connection to the MQTT broker.

› Type:Boolean
› Default:true
› Signal:autoSubscribeChanged()
› Attributes:Writable

error

This property holds the most recently occurred error or MqttAbstractSubscription.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

qos

This property holds the Quality of Service to set for the subscribed topics. The QoS level defines how hard the broker will try to ensure that a message is received. MQTT defines three QoS levels:

  • 0: The broker will deliver the message once, with no confirmation. This level could be used, for example, with ambient sensor data where it does not matter if an individual reading is lost as the next one will be published soon after.
  • 1: The broker will deliver the message at least once, with confirmation required.
  • 2: The broker will deliver the message exactly once by using a four step handshake. This level could be used, for example, with billing systems where duplicate or lost messages could lead to incorrect charges being applied.
› Type:SignedInteger
› Default:0
› Signal:qosChanged()
› Attributes:Writable

subscribed

This property holds whether the topics have been subscribed successfully.

› Type:Boolean
› Default:false
› Signal:subscribedChanged()
› Attributes:Readonly

Methods

subscribe()

This method subscribes the configured topics using the parent MqttClient object. Once subscribed the MqttTopic::data properties are updated whenever the MQTT broker receives updates from the topic publisher.

This method usually never has to be called manually. Instead the autoSubscribe property should be left at its default value or set to true.

unsubscribe()

This method unsubscribes the configured topics using the parent MqttClient object. The MqttTopic::data properties will not be updated any longer if the MQTT broker receives updates from the topic publisher.

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

Enumerations

Error

This enumeration describes all errors which can occur in MqttAbstractSubscription objects. The most recently occurred error is stored in the error property.

Name Value Description
MqttAbstractSubscription.NoError 0 No error occurred or was detected.
MqttAbstractSubscription.InvalidClient 1 Parent object is not an MqttClient.