Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 14 Next »

This is a community built MQTT connector from Stackhub

Overview

The PahoMqtt Extension implements MQTT client subscription and publication to topics on an MQTT broker where messages on those topics contain current point values. It uses the Eclipse Paho MQTT java client for all MQTT Broker communication. This extension depends on pahoMqtt which is just a wrapper for the runtime Java jar files it requires.

Discovery and learn are not supported functions. As a result, brokers are not discoverable from within the Connectors app and from within the Builder app, the Connectors panel will not show the PahoMqtt Connector.

All PahoMqtt proxy points must be manually bound.

History synchronization is not supported by PahoMqtt. You will need to use History Collected to store history.

Prerequisites

Download and install the latest of these pods for the current framework version being used:
pahoMqtt v1.2.1 - do not use v1.2.2!
pahoMqttExt v1.0.14 - do not use v1.0.15!

Once installed, go to the Settings app → Ext → and enable Paho MQTT.

Creating a MQTT connector

Source documentation available here.

The MQTT connector can be added via the DB Builder → Connectors tree under the PahoMqtt.

The connector URI has the following format:

tcp://[IP]:[port]

where:

  • IP – the IP address of the MQTT device

  • port - default for MQTT is 1883

If username is entered, then a password is also expected. These will be supplied to the broker on connection. If you have a non-authenticating broker, just leave username and password blank.

Additionally, the tag below needs to be added to the connector if there are points that are writable.

  • pahoMqttQos (number tag) - value being either 0, 1, or 2. Recommend setting it to 1. There is no difference between those values.

Adding data points

This portion has to be done manually. Each point has to be created and have a reference to the MQTT connector. More documentation from Stackhub about “Parser” and “PointName” can be found here and look for those sections.

First, the user needs to create a local point in DB Builder.

Then add the following tags to read the current value:

Tag name

Required

Tag type

Details

Notes

pahoMqttCur

yes

string

/point/current/topic

pahoMqttConnRef

yes

reference

@id_of_mqtt_connector

pahoMqttPointName

optional

string

pointName

pahoMqttParser

optional

string

functionName

parses the json into readable content

To make a point writable, it needs to have these additional tags.

Tag name

Required

Tag type

Details

Notes

pahoMqttWrite

yes

string

/point/write/topic

pahoMqttPointName

optional

string

pointName

pahoMqttConstructor

optional

string

functionName

constructor function to output json

The pahoMqttParser and the pahoMqttConstructor tag can also be applied on the connector itself; they will then apply to all points.

Examples

Reading a raw value

How to read a value if the topic contains just a raw value.

Reading a raw value with multiple variables

How to read a value based on the variable name (if the topic contains more variable names).

Reading a json value

How to read the value in json format.

  • Under Advanced Apps, click on Funcs, then create a new function, name it as you prefer and paste the below code:

(msg, params : null) => do
  json: ioReadJson(msg)
  return json
end
image-20250115-123824.png
  • Proceed tagging the point:

read_json.png

Here is the json content used in the above example:

{
  "jsonValue0": 15,
  "jsonValue1": 25
}

Writing a value

How to write to a point when sending single values.
Go to the Funcs app

  1. Create a new func called pointWriteSimpleVal

  2. Copy the code to the right and paste into the func and save it.

  3. Create the pahoMqttConstructor tag, either in the point to be written or in the connector, and give it the “pointWriteSimpleVal” value.

  4. Disable/enable the MQTT connector.

(pt, val) => do
  if (val != null) do
    if (val.isDict) return val->writeVal.toStr
    else return val.toStr
  end
  return  "NULL"
end
  • No labels