LLExec MQTT Engine

From Axel Public Wiki
Jump to navigation Jump to search

The Axel Plc Runtime integrated MQTT Engine allows PLC Programs to publish automatically variable values to any MQTT broker.
It also allows to subscribe the PLC to some Topic on MQTT Broker and updates automatically variable values.
No coding effort is required, it can be interely configured in the LogicLab resources View.
Screenshot01.png Right clicking on the MQTT icon is possible to add an MQTT Broker to which publish the variables, or to to subscribe to for Topics.

Any PLC application can connect to any number of broker.

Connection Tab

Screenshot02 ConnectionTab.png This tab is organized in two sections, Configuration and Defaults.
Defaults reppresents default values for every entry in the other tabs, wich options will be showed later.
The configuration has many fields, as follow:

  • Client name: is the name with which the runtime presents itself to the broker, must be unique for any broker.
  • IP Address: is the IP address, or full qualified name of the broker
  • Port: is the tcp port of the broker
  • TLS: it specify if the connection to the broker is secure and encrypted
  • Common name server: can be the full qualified name of the server, or the common name in the server’s certificate.
  • Username: for the connection to the broker
  • Password: for the connection to the broker.

Note on TLS: with TLS option on all the communication will be encrypted.
Another feature of the TLS is that both Broker and client should present itselves with a certicate issued from a Certificate Authority. This ensure the identity of both broker and PLC, but the PLC may not have a valid certificate.
In this case a self provided certificate can be used, it shuould be installed in the runtime folder:

  • ca.cert.pem: it’s the Certificate Authotity’s certificate
  • client.cert.pem: it’s the PLC’s certificate
  • client.key.pem: it’s the privare key of the PLC

For more information please refer to the online documentation of OpenSSH.
If you are using a self signed certificate for the PLC, the broker may be required to allow unsecured connections.

Publish tab

Screenshot03 PublishTab.png In the publish tab, variables engaged to be published to the selected broker can be selected,
also many publish parameters can be selected.
With the Add, Remove and Assign the variables can be selected,
the engine manage to publish cyclically the value or on variataion.
All the parameters take the default value expressed in the Connection tab.
The columns and parameters are:

  • Variable name: it can be any global variable or expression (ie a member of a global variable structure).
  • Topic: the name of the topic related to this variable values - the name of the topic is composed by the prefix and the variable name. The name of the topic can be changed if desired.
  • Read only: this flag is true by default, if this field is false then an addictionally topic is implicitally created: the main topic name plus “/set” . The engine subscribe itself to this implicit topic, doing so an external mqtt client can write the variable publishing a value to the set topic.

For example if the variable main topic is /myPrefix/cnt a client can write the cnt value publishing a value to the topic /myPrefix/cnt/set

  • QoS (Quality of Service): MQTT allow three quality of service:
    • 0 – every message is sent without confirmation from the broker
    • 1 – for every message sent, the broker sends a confirmation
    • 2 – also the confirmation is acknoledged to the broker, this guaratees that only one value is written for the topic, no packets duplication.

The quality of service is bundled to every message and impacts the communication from the publisher to the broker as well as the communication from the broker to the subscriber. In this latter case the behaviour is what is specified for the less value of QoS between the message and the subscription. As an example: publisher A send a message to the broker with QoS 2: this mean that the brocker will confirm the message and the publisher will acknoledge the confirmation as well. A subscriber B suscribes to that topic with QoS zero. The message has e QoS 2 but the subscribtion has QoS 0, so the zero policy is selected since is the lower value. The broker so will send the message to the subscriber B without expecting any confirmation, as specified by the QoS 0. - Retain: this specifies if the messages have the attribute retain. If a message has this attribute, when a subscriber subscribes to a topic, a message with the last value is sent to the subscriber. Otherway a message is sent to the subscriber only at the time a value is published. - Payload: the payload can be binary or json. If binary is selected then the raw binary value of the variable is sent, if json is selected the value is sent in human readable json format, with two fields: one specifying the value, the other specifitying a timestamp. The names of the two fields can be selected as desired. At the moment no structured type is allowed to be sent with json payload. - Send on variation: if selected the variable value is published to the broker in case a variation greater than a specified threshold has been detected. - Threshold: is the threshold for the “Send on variation” mode. - Inhibit time: this prevents too message will be sent if a too fast variation occours. - Polling time: this can set a period after which the value is sent, despite its variation. - JSON value name: Is the name to the value field, if json payload format has been selected. - JSON timestamp name: Is the name to the timestamp field, if json payload format has been selected.