Table of Contents |
---|
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.
NOTE: This is a community built MQTT connector from Stackhub.
Prerequisites
Download and install the latest of these pods for the current framework version being used:
pahoMqtt (latest for FIN 5.0 and 5.1 is v1.2.1)
pahoMqttExt (latest for FIN 5.0 and 5.1 is v1.0.14)
Once installed, go to the Settings app → Ext → and enable Paho MQTT.
Creating a MQTT connector
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 two tags below need to be added to the connector.
pahomqttQos (number tag) - value being either 0, 1, or 2. Recommend setting it to 1. There is no difference between those values.
pahoMqttConstructor (string tag) - value being the name of a function we’ll be creating called pointWriteSimpleVal.
Creating the function
Go to the Funcs app
Create a new func called pointWriteSimpleVal
Copy the below code and paste into the func and save it.
That’s it, now we recommend to disable/enable the MQTT connector.
Code Block |
---|
(pt, val) => do if (val != null) do if (val.isDict) return val->writeVal.toStr else return val.toStr end return "NULL" end |
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:
pahoMqttCur (required - string type): /point/current/topic
pahoMqttConnRef (required - ref type): @id_of_mqtt_connector
pahoMqttParser (optional - string type): funcName
pahoMqttPointName (optional - string type): pointName
To make a point writable, it needs to have these additional tags.
pahoMqttWrite (required - string type): /point/write/topic
pahoMqttConstructor (optional - string type): constructorName
pahoMqttPointName (optional - string type): pointName
Examples
How to read a value if a topic contains just a value.
How to read a value based on the variable name (if the topic contains more variable names).
How to read the value from a json.