Publish Tag Value to from Ignition SCADA to MQTT Broker on Tag Value Change


Publish Tag Value to from Ignition SCADA to MQTT Broker on Tag Change

If you are using Ignition SCADA and want to publish tag values to an MQTT broker on Tag Change, then you've come to the right place. In this blog post, we will guide you step-by-step on how to do just that.

Prerequisites

Before we get started, make sure you have the following:

  • Ignition SCADA installed and running
  • MQTT Engine Module is Installed along with Ignition SCADA
  • MQTT broker (such as Mosquitto) installed and running
  • Make Sure that Ignition SCADA is Connected to MQTT Broker using MQTT Engine Module
Step 1: Create a Tag

First, you need to create a tag in Ignition that you want to publish to the MQTT broker. To do this, go to the Ignition Designer, click on the "Tag Browser" on the left-hand side, and then click on the "+" icon to create a new tag.

Step 2: Configure Tag Properties

Once you have created the tag, you need to configure its properties. Make sure that the "Tag Value Source" is set to "Memory", and the "Data Type" is set to the appropriate type for your tag (such as Integer, Float, Boolean, etc.).

Step 3: Create a Gateway Event Script

Next, you need to create a gateway event script that will publish the tag value to the MQTT broker when the tag value is change.

To do this, go to the "Scripting" then Double Click on “Gateway Events”

Create “Tag Change” Script and Set “Script Name”. Next Set “Change Triggers” to “Value” and Paste the “Tag Path” in “Tag Path(s)” Window

In the script, you have to define Tag Value which we will read to Publish When it’s get change. And We will define on which Broker we want to publish that value and on which topic we want to update the value.

Here is an example script:

buff = system.tag.read("MyTAGPath")
system.cirruslink.engine.publish("MyBroker", "myTopic", str(buff.value).encode(), 0, 0)

Make sure to replace MyTAGPath with the Path of your tag, and myTopic with the topic you want to publish to on the MQTT broker, and MyBroker with the Broker Name which we have defined in Prerequisites.

Step 4: Test the Script

Now that you have created the script, you can test it by changing the Tag Value. Don’t forgot to save the project otherwise it will not work.

If everything is working correctly, you should see the tag value being published to the MQTT broker.

Conclusion

In this blog post, we have shown you how to publish tag values from Ignition SCADA to an MQTT broker on Tag Change. By following these steps, you can easily integrate your Ignition SCADA system with other systems that use MQTT.

We hope you found this blog post helpful. If you have any questions or comments, feel free to leave them below.

Comments