Prerequisites:


Overview:

MQTT Engine provides a mechanism for publishing MQTT Messages from an Ignition script.  This can be useful for general messaging outside of Sparkplug.  For example, one may want to interface to another system that uses MQTT.  This method allows arbitrary MQTT messages to be published based on events that exist in Ignition.


MQTT Message Publishing via Ignition Script:

Start by opening an Ignition Designer window and double clicking 'Project-> Gateway Event Scripts' from the Project Browser as shown below:

Now select 'Tag Change' click the 'new Tag' icon at the bottom of the window shown below.

Set the name of the script and then select a tag path.  In this case we're using an MQTT Engine tag from an emulated device.

Now select the 'Script' tab near the top.  In it, type the following line:

system.cirruslink.engine.publish("Chariot SCADA", "a/b/c", str("hello world").encode(), 0, 0)

Note, the form of the publish method is as follows.  You may need to change the method arguments based on your configuration:

system.cirruslink.engine.publish(String serverName, String mqttTopic, byte[] payload, int qos, boolean retain)

Where:

  • serverName: The server name as shown in the MQTT Engine Settings configuration shown below
  • mqttTopic: The MQTT Topic to publish on
  • payload: The MQTT payload
  • qos: The MQTT quality of service to publish on
  • retain: Whether or not to set the retain flag in the MQTT message

When complete, the script should look something like this.  Now click OK.

Finally, save and publish the project.  At this point every time this tags value, quality, or timestamp changes it will result in a MQTT message being published on topic 'a/b/c' with a payload of 'hello world'.

Additional Resources

  • No labels