Customizing MQTT connections

Dear Supporters,

in our community we need to count on, let’s call it, sort of “exotic” hardware cards/devices which do not support OPC-UA connections nor any one of the predefined in the OPC standard connections provided by Ignition. Therefore, we want to explore the potential of MQTT for this aim. Because of the nature of the hardware we have, we won’t be able to set a standard MQTT architecture, with an Ignition-edge connecting to the hardware through the transmission module, so we will have a certain linux machine which will run a python script connecting the the Ignition gateway instance which has both, the MQTT server and the engine. Take into account, that for our particular case, the hardware will provide us with just 5 topics. So, I can perfectly retrieve these 5 values, let’s say it, by hand. I have therefore several questions:

  1. Is this approach possible and recognised by Ignition?. This means, can I publish topics into the broker with a python script and the engine module available in the gateway will still be able to subscribe to the mentioned topics and create the corresponding tags?
  2. What is the broker_address to provide into the code?. I am just trying the following initial code:

import os, sys
import paho.mqtt.client as mqtt

broker_address=“ip_address_of_the_machine_hosting_the_gateway”

client = mqtt.Client(“P1”)
client.connect(broker_address)
client.publish(“house/main-light”,“OFF”)

However when I run it it tells me “socket.error: [Errno 111] Connection refused”, so it is failing at the connect level. Therefore the question is, how can I connect to the MQTT server that I have installed using the corresponding module in Ignition, using an external python script? (btw, just for testing, the python script I am creating is being executed in the same machine where the MQTT server and the gateway are installed, so I do not have any firewall issue).

Thank you very much for your help,
Patricia

You definitely can leverage ad-hoc MQTT topic namespaces by adding a custom namespace definition in the MQTT Engine configuration. If you use JSON for your payload, MQTT Engine will automatically create tags representing the object structure you publish to a given topic.

Take a peek at the MQTT Engine configuration documentation on Cirrus Link’s website for more details.

With this approach you can certainly connect any type of MQTT clients to your infrastructure. One thing to keep in mind is that one of the primary interests of the Sparkplug topic/payload definition is for ensuring that you can track “state”. It serves as the glue atop MQTT to facilitate being able to trust that you have the latest data from a given device and that the connection is healthy. Take a look at the Tahu specification for more details. (there are also some example client libraries, including Python, for building your own custom MQTT/Sparkplug clients)

Lastly, make sure that you have the port for your MQTT broker (1883/tcp by default) open in your firewall–you may need to add a rule to accept inbound traffic.

Hope this helps!

Kevin C.

1 Like

Thank you so much for your prompt answer. I will go deeply through the documentation you suggested me and I might come back for further questions.

Regarding the connection, indeed it was a matter of setting the role for the port 1883. I have just established the connection successfully.
Thanks again,
Patricia