|
The Xentara MQTT client v2.2
User Manual
|
Commands are Xentara elements that allow you to receive commands from by an MQTT client element by subscribing to an MQTT topic. Command elements must always be children of client elements.
Each command element has the following properties:
The MQTT client requires the payload of all messages received on the command topic to be formattes as a JSON text compliant with RFC 8259. When a message on the subscribed topic is received from the broker, the MQTT client will attempt to parse the payload and write the resulting values to writable Xentara data points.
The configuration of the command contains a list of data points to write whenever a message is received on the subscribed topic. Each of the data points entries has the following properties:
For each data point the corresponding JSON value is located with the received message payload, and the corresponsing value is written to the data point. The process of decoding the values is described in the next chapter.
Normally, the JSON value found is decoded, and the resulting value is written to the data point using the appropriate data type:
Other JSON types (objects, array, and NULL values) are not supported and will result in a type mismatch error.
Sometimes, however, it can be more useful to write the original JSON text to the data point as a string, and then decode the value using a purpose-written microservice. This can be accomplished using the Xentara C++ Control skill, for example. This allowes you to do more sophisticated parsing of the JSON value, including parsing JSON objects and JSON arrays. To use a microservice to decode the JSON value proceed as follows:
| key | The command’s primary key. | ||||||||
| name | The command’s name. The name is the last component of the primary key. | ||||||||
| UUID | The unique UUID of the command. | ||||||||
| type | The command’s element type. For MQTT commands, this is always “MQTT Command”. | ||||||||
| category | The command’s category. For MQTT commands, this is always “transaction”. | ||||||||
| brokerAddress | The host name or network address of the broker the command’s client connects to. | ||||||||
| portNumber | The port number of the broker the command’s client connects to. | ||||||||
| clientID | The MQTT client identifier the command’s client advertises to the broker on connection. | ||||||||
| topic | The MQTT topic the command subscribes to. | ||||||||
| state | A Boolean value denoting whether the topic was subscribed to successfully. This attribute will be true if the topic is was subscribed to successfully, or false if there was a problem. | ||||||||
| subscribeTime | The time the topic was subscribed to, or the time the subscribe error occurred if the subscription failed. | ||||||||
| subscribeError | This attribute contains an error message denoting the error if the “state” attribute is false. | ||||||||
| receiveTime | The time a message was received. | ||||||||
| QoS | The numeric value of the MQTT QoS (quality of service) of the last received message. MQTT defines the following three QoS values:
| ||||||||
| retained | Whether the last received message was a message that will be retained by the broker. This will cause the message to be received again if the connection to the broken is lost and reestablished. The retained flag is set by the publisher of the message. | ||||||||
| receiveErrorSummary | This attribute contains a text summarizal any errors that occurred decoding the last message payload, or writing the data to the data points. |
| received | This event is raised whenever a message has been received on the subscribed topic. |
JSONPath is a language that allows you to specify a “path” to a specific value within a JSON document. The Xentara MQTT client only supports a subset of the JSONPath specification. The following selectors are supported:
Consider the following payload:
You can extract the individual values from this payload using the following JSONPath queries:
| Value | JSONPath Query |
|---|---|
| intake temperature | $.temperatures.intake |
| exhaust temperature | $.temperatures.exhaust |
| pressure #1 | $.pressures[0] |
| pressure #2 | $.pressures[1] |
| class of status #1 | $.status[0].class |
| confidence of status #1 | $.status[0].confidence |
| class of status #2 | $.status[1].class |
| confidence of status #2 | $.status[1].confidence |
You can also extract the entire “status” array using the query “$.status”, or the entire “temperatures” block using the query “$.temperatures”. This is only useful, however, if you selected the option “as JSON text” for the data point, because the normal decoding of JSON values only supports strings, numbers, and Boolean values.
To extract the whole JSON message, use just the query “$”.