pahoMqttExt

MQTT Connector based on Paho mqtt client library
pahoMqttExt

Registered users on StackHub may elect to receive email notifications whenever new package versions are released.

v1.0.3

Axon functions

pahoMqttConstructJson
pahoMqttConstructJson(pt, val, level: null)
Fantom signature:
@Axon const static Str pahoMqttConstructJson(Dict pt, Obj? val, Number? level := null)
pahoMqttParseCsv
pahoMqttParseCsv(msg, params: null)

MQTT message parser that is passed the payload as a String and parses it as a comma separated set of values.

Default column separator is , and expected value positions are "curVal","curStatus" To override this pass in a Dict as an optional second parameter. The Dict should contain the tags colSep and colNames. colSep is a single character Str and colNames is Str[]

If there are more values than column names supplied, default colnames of v1..vn are used. If curStatus is not one of the column names curStatus will be set to "ok"

This function abides by the contract for MQTT message parsers in taking a Str as its first parameter and returning a Dict with curVal and curStatus tags.

Configure it on the connector either just as the function name or follow it with a Dict containing colSep and colNames tags. e.g.

pahoMqttParseCsv {colSep:",", colNames:["curVal","curStatus"]}
Fantom signature:
@Axon const static Dict pahoMqttParseCsv(Str msg, Dict? params := null)
pahoMqttParseJson
pahoMqttParseJson(msg, params: null)

MQTT message parser that is passed the payload as a String and parses it as a JSON object.

The JSON Object structure is fixed. It expects the outer object to contain an array of metric objects, with the property name metrics. Each metric object in the array must have a name and a value property.

Fantom signature:
@Axon const static Dict pahoMqttParseJson(Str msg, Dict? params := null)
pahoMqttParseVal
pahoMqttParseVal(msg)

MQTT message parser that is passed the payload as a String and uses it as the point curVal. It assumes point curStatus is "ok". Units should not be in the message body.

If no MQTT parser is configured on an PahoMqtt Connector or point, this is the default parser used.

This function abides by the contract for MQTT message parsers in taking a Str as its first parameter and returning a Dict with curVal and curStatus tags.

Fantom signature:
@Axon const static Dict pahoMqttParseVal(Str msg)
pahoMqttPing
pahoMqttPing(conn)

Ping a PahoMqtt connector

Examples:

read(pahoMqttConn).pahoMqttPing
pahoMqttPing(pahoMqttConnId)

Side effects:

  • Obtains the Version for the MQTT Broker this connector is connected to
Fantom signature:
@Axon { admin=true; } const static Obj? pahoMqttPing(Obj conn)
pahoMqttSyncCur
pahoMqttSyncCur(proxies)

Subscribe all the proxy points to their MQTT topic on the MQTT Broker. Current value with asynchronously arrive on the next message received for the topic. If there is a retained message for the topic, current value will arrive almost immediately. The proxies may be any value supported by toRecList.

Each proxy point must contain:

Side effects:

  • performs async network IO to subscribe to the point val topics
  • updates curVal tag transiently
  • updates curStatus tag transiently
  • updates curErr tag transiently
Fantom signature:
@Axon { admin=true; } const static Obj? pahoMqttSyncCur(Obj proxies)
Published by Crowley Carbon

Packages by Crowley Carbon

Free packages