cpMqttExt icon

cpMqttExt

Cool Planet MQTT Connector Extension
cpMqttExtAxon 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 0 watchers.

v2.1.3

cpMqttClientClose
cpMqttClientClose(client)

Close the provided MqttClient

Fantom signature:
@Axon static Void cpMqttClientClose(MqttClient client)
cpMqttClientConnect
cpMqttClientConnect(cfg)

Create an instance of an MqttClient, connect and return it This is unrelated to Connector functionality The Dict parameter provided may contain the following url - (Str or Uri). Format is mqtt://host:port or mqtts://host:port username password - Plain Text certFile - If client cert file auth is being used (alternative to username/password) keyFile - Must be supplied if certFile is used clientId - to override a default UUID generated client ID

Fantom signature:
@Axon static MqttClient cpMqttClientConnect(Dict cfg)
cpMqttClientPublish
cpMqttClientPublish(client, msg, topic, qosNum)

Publish a message to the specified topic using the provided MqttClient. Return the same provided client to it can be used again in a chain of commands

Fantom signature:
@Axon static MqttClient cpMqttClientPublish(MqttClient client, Str msg, Str topic, Number qosNum)
cpMqttConstructJson
cpMqttConstructJson(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 cpMqttConstructJson(Dict pt, Obj? val, Number? level := null)
cpMqttMigrateFromPaho
cpMqttMigrateFromPaho()

Migrate all existing Paho based MQTT Connectors and Points to CP MQTT based A restart of SkySpark will be required once this completes.

cpMqttParseCsv
cpMqttParseCsv(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.

cpMqttParseCsv {colSep:",", colNames:["curVal","curStatus"]}
Fantom signature:
@Axon static Dict cpMqttParseCsv(Str msg, Dict? params := null)
cpMqttParseJson
cpMqttParseJson(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 cpMqttParseJson(Str msg, Dict? params := null)
cpMqttParseVal
cpMqttParseVal(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 CpMqtt 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 cpMqttParseVal(Str msg)
cpMqttPing
cpMqttPing(conn)

Ping a CpMqtt connector

Examples:

read(cpMqttConn).cpMqttPing
cpMqttPing(cpMqttConnId)

Side effects:

  • Obtains the Version for the MQTT Broker this connector is connected to
Fantom signature:
@Axon { admin=true; } static Obj? cpMqttPing(Obj conn)
cpMqttPublishMsg
cpMqttPublishMsg(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 mqtt://host:port or mqtts://host:port topic - What topic to publish to msg - Supports String messages only

Optionally you can also provide: username password - Plain Text certFile - If client cert file auth is being used (alternative to username/password) keyFile - Must be supplied if certFile is used clientId - to override a default UUID generated client ID qos - Int 0|1|2

Fantom signature:
@Axon static Void cpMqttPublishMsg(Dict cfg)
cpMqttRevertToPaho
cpMqttRevertToPaho()

Revert all existing CP based MQTT Connectors and Points to Paho MQTT based A restart of SkySpark will be required once this completes.

cpMqttSyncCur
cpMqttSyncCur(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? cpMqttSyncCur(Obj proxies)

Packages by Cool Planet Clarity Ltd

Free packages