MqttMeasurementWriter
Description
The MqttMeasurementWriter object is a special MqttPublication object which publishes a set of Measurement objects in a certain topic structure or data format. The Object.objectId property of each measurement is used as the corresponding key in the measurements JSON/CBOR array (in MqttMeasurementWriter.JsonMap or MqttMeasurementWriter.CborMap mode) or to construct the topic name (in MqttMeasurementWriter.TopicTree mode).
This object was introduced in InCore 2.5.
- › Inherits:
Overview
Properties
Methods
Signals
Enumerations
Properties
bufferDatabase
This property holds the database to which the measurements are written temporarily when MeasurementBufferDatabase.buffering is set to true and the MQTT client is not connected to a broker.
- › Type:
- › Signal:
bufferDatabaseChanged()
- › Attributes:
Readonly
container
This property holds a map with keys/values in which to embed the JSON/CBOR data in the measurementsFieldName field. This allows publish additional metadata such as the device name or location. If empty, the string representation of the JSON/CBOR data is published directly.
- › Type:
Map
- › Signal:
containerChanged()
- › Attributes:
Writable
fields
This property holds a combination of MqttMeasurementWriter.Field flags specifying which properties of each Measurement to publish.
- › Type:
- › Default:
enumitem{MqttMeasurementWriter::Field::}
- › Signal:
fieldsChanged()
- › Attributes:
Writable
grouping
This property holds whether an additional hierarchy level for measurement groups should be used. When enabled, the Object.objectId associated with the objects is added to topicBaseName or inserted in the JSON/CBOR map.
- › Type:
Boolean
- › Default:
false- › Signal:
groupingChanged()
- › Attributes:
Writable
measurementsFieldName
This property holds the name of the field in the container map in which to embed the JSON/CBOR-encoded measurements.
- › Type:
String
- › Default:
measurements- › Signal:
measurementsFieldNameChanged()
- › Attributes:
Writable
mode
This property holds the mode specifying how the measurements are published.
- › Type:
- › Default:
- › Signal:
modeChanged()
- › Attributes:
Writable
topicBaseName
This property holds a string which to prepend to the topic name of all publications.
- › Type:
String
- › Signal:
topicBaseNameChanged()
- › Attributes:
Writable
Enumerations
Fields
This enumeration describes flags for fields which the writer can publish.
Name |
Value |
Description |
|---|---|---|
|
|
publish the DataObject.data property. |
|
|
publish the DataObject.timestamp property. |
|
|
publish the DataObject.name property. |
|
|
publish the DataObject.description property. |
|
|
publish the Measurement.unit property. |
|
|
publish the Measurement.siPrefix property. |
|
|
publish the Measurement.decimals property. |
|
|
publish the MeasurementView.range property. |
Mode
This enumeration describes all supported modes in which the writer can operate.
Name |
Value |
Description |
|---|---|---|
|
|
publish measurements and their properties in subtopics, e.g. |
|
|
publish measurements and their properties as a JSON map. |
|
|
publish measurements and their properties as a CBOR map. |
|
|
publish measurements and their properties as a JSON array. |
|
|
publish measurements and their properties as a CBOR array. |
Example
import InCore.Foundation 2.5
import InCore.Mqtt 2.5
Application {
ObjectArray {
id: measurements
MeasurementGroup {
objectId: "weather"
Measurement {
objectId: "temperature"
name: "Temperature"
data: 25
dataType: Measurement.Float
unit: Measurement.DegreeCelsius
property var t: Timer { onTriggered: parent.data += Math.random() - 0.5 }
}
Measurement {
objectId: "humidity"
name: "Relative humidity"
data: 65
dataType: Measurement.SignedInteger
unit: "%"
property var t: Timer { onTriggered: parent.data += Math.random() - 0.5 }
}
}
}
MqttClient {
clientId: "MqttMeasurementWriterExample"
hostname: "localhost"
MqttMeasurementWriter {
qos: 1
retain: true
topicBaseName: "weather"
grouping: true
submitMode: MqttMeasurementWriter.SubmitOnCompleteDataset
mode: MqttMeasurementWriter.JsonMap
fields: MqttMeasurementWriter.Timestamp | MqttMeasurementWriter.Value |
MqttMeasurementWriter.Name | MqttMeasurementWriter.Unit
Gather on objects {
source: measurements
typeFilter: Measurement {}
}
}
}
}