pahoMqttExt icon

pahoMqttExt

Paho MQTT Connector Extension
pahoMqttExtAxon funcs

Registered StackHub users may elect to receive email notifications whenever a new package version is released or a comment is posted on the forum.

There are 9 watchers.

v1.0.15

pahoMqttConstructJson
pahoMqttConstructJson(pt, val, level: null)

MQTT message constructor that is passed the point record, value and level

The JSON Str returned is an outer object containing an array with the property name metrics. The single object in the array has a name and a value property, and optionally a level property if provided

Example returned JSON Message:

{
   "metrics":
  [
      {"name":"pt1","value":73.0,"level":1}
  ]
}  
Fantom signature:
@Axon 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 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.

Example JSON Message:

{
   "metrics":
  [
      {"name":"pt1","value":73.0},
      {"name":"pt2","value":true},
      {"name":"pt3","value":"string val"}
  ]
}

results in this Dict:

{pt1:73.0, pt2:true, pt3:"string val"}
Fantom signature:
@Axon 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 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; } static Obj? pahoMqttPing(Obj conn)
pahoMqttPublishMsg
pahoMqttPublishMsg(cfg)

Provide a function that publishes a message to a broker on a topic This is unrelated to Connector functionality The Dict parameter provided must contain the following url - (Str or Uri). Format is tcp://host:port or ssl://host:port topic - What topic to publish to msg - Supports String messages only

Optionally you can also provide: username password - Plain Text clientId - to override a default UUID generated client ID cleanSession - Bool true|false qos - Int 0|1|2 retained - Bool true|false

Fantom signature:
@Axon static Void pahoMqttPublishMsg(Dict cfg)
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; } static Obj? pahoMqttSyncCur(Obj proxies)

Packages by Cool Planet Clarity Ltd

Free packages