Skip to content

MQTT Sparkplug Auto-Discovery Using PLCnext Gateway, HiveMQ Broker and Ignition SCADA

by Kudzai Manditereza
16 min read

In this article, I’m going to demonstrate how to generate MQTT Sparkplug telemetry data from a PLCnext Programmable Logic Controller, transmit the data to a HiveMQ Cloud MQTT broker and visualise the information using the Ignition SCADA platform.PLCnext Technology Starter KitTo demonstrate, I’m going to use this PLCnext Technology Starter Kit which consists of a controller, I/O modules, potentiometer, and some buttons. I am going to collect data generated by the potentiometer and buttons, publish them as Sparkplug messages to a HiveMQ Broker hosted in the cloud. And on my PC, I’m running an Inductive Automation’s Ignition Gateway which will connect to the HiveMQ Broker and pull all the data for visualization.

Architecture

One of the biggest challenges in integrating data from industrial data sources is the ability to automatically discover components that are producing the data. The simplest way to achieve that, is to connect my data sources to an MQTT Sparkplug network. In this demo, I’m going to showcase how, using an MQTT Engine Module, the Ignition SCADA platform can automatically discover my PLCnext Controller and visualize the telemetry data that it is generating.Data Source, HiveMQ Cloud and Data Consumer DiagramTo enable my PLCnext Controller to participate in an MQTT Sparkplug Network, I’m going to deploy onto the controller, a PLCnext Edge Gateway, which is a software runtime that effectively turns my controller into a Sparkplug Edge of Network Node. For coordination of the discovery process and exchange of information, both components are going to be connected through a cloud-based HiveMQ MQTT Broker.

Installing PLCnext Edge Gateway

To deploy the PLCnext Edge gateway, go to the Phoenix Contact website:

Once on this page, I can then download the PLCnext Edge Gateway installer.Download the PLCnext Edge Gateway installerNext, I’ll make sure my controller is on the same network as my computer and then run the installer.Controller is on the same network as the computerI’ll enter the IP address of my controller into the Axiocontrol IP address field.enter the IP address of the controller into the Axiocontrol IP address fieldI’ll now enter the admin password of my controller.

Then click Next.

Okay, my connection is successful.Successfully connectedNext, I select the Install via Web option to download and transfer the latest version of PLCnext Edge Gateway onto my controller.Install via Web option to download and transfer the latest version of PLCnext Edge GatewayOnce the PLCnext Edge Gateway has finished installing, we can go ahead and open the web interface.open the web interfaceI’ve entered the IP address of my controller to access my PLCnext Edge Gateway interface.Entering the IP address of the controller to access my PLCnext Edge Gateway interface.And when the interface has loaded, I then click on ADD under drivers at the bottom to add my Sparkplug driver. Then I enter my password.

These are the drivers that are currently available for me to enable.Drivers that are currently available for me to enableI enable Sparkplug, and then open my Sparkplug driver interface.Sparkplug details which include the broker URL address, its credentials and the Sparkplug topic namespace.This is where I enter my Sparkplug details, which include the broker URL address, its credentials, and the Sparkplug topic namespace.
Sparkplug details which include the broker URL address, its credentials and the Sparkplug topic namespace.But first, let’s provision my HiveMQ Cloud Broker to get the broker details.

Setting Up HiveMQ MQTT Broker

I need to setup my HiveMQ MQTT Broker on HiveMQ Cloud so that I can point my PLCnext Edge Gateway to this broker and start publishing Sparkplug messages to it. With the HiveMQ website on my browser I’ll proceed by selecting Login on the mega menu.

When the HiveMQ Cloud page is open, scroll down to the options table. Here I’ll sign up for the free version, which allows me to connect up to a hundred devices. Click on Sign up now.

I’m taken to the HiveMQ Cloud portal home page and I sign up using my Google account. Here I can select a Cloud provider where I want my HiveMQ Broker Cluster to be hosted.select a Cloud providerI’ll select AWS.

Next, I need to set up credentials that MQTT clients can use to connect to this broker.set up credentials that MQTT clients can use to connectI’ve successfully created a free HiveMQ Cloud account.Successfully created a free HiveMQ Cloud accountWhen I click on Clusters option on the side menu, a broker cluster has been automatically provisioned for me.A broker cluster has been automatically provisionedTo start publishing to this MQTT broker, I’ll need to get the broker details to put on my PLCnext Edge Gateway.

To do that, I’ll click on Manage Cluster, and then copy my MQTT broker hostname or URL address.Copy the MQTT broker hostname or URL addressNotice that communication with this broker is secured using TLS encryption at port 8883.

In case I need to update my MQTT client access credentials, I’ll click on Access Management.Access Management TabHere I can delete the existing username and password and assign new access credentials.

The MQTT Broker setup on HiveMQ Cloud portal is complete. The next step is to configure my PLCnext Gateway to start publishing Sparkplug telemetry messages to my HiveMQ MQTT Broker.

Configuring PLCnext Edge Gateway

Going back to my PLCnext Edge Gateway interface, I’ll go ahead and input my HiveMQ Broker URL address and access credentials that were created.PLCnext Edge Gateway interfaceThen click on submit.

So, I’ve successfully added a Sparkplug Driver to my PLCnext Edge Gateway, and the status of the driver is Connected.Adding a Sparkplug Driver to my PLCnext Edge GatewayNow that I’ve succesfully connected the Sparkplug driver to my HiveMQ MQTT Broker, the next step is to configure the metrics that the Sparkplug driver needs to push to the broker.

To do that, I’ll click on the driver.Sparkplug Driver DetailsClick the button to add a new metric.

Select Data Source.Selecting the Data Source on PLCnext Edge GatewaySelect Downstream.If I had my gateway connected to downstream Modbus devices, for example, they’d show up here and I’d add their data as Sparkplug metrics. But in my case, my source of data are IO modules on my PLCnext controller.

So I’ll select Axioline. Go to Modules. Go to My Analog Input Module. Channel 1. And I have a voltage value.Go to My Analog Input Module and Channel 1If I move the slider on the Starter Kit, the value of voltage changes.

I’ll select it,assign it a name, Voltage. I’ll specify the data type as rea and select to update on change. Then I’ll click on submit to add the metric.click on submit to add the metric for voltageI’ve added the digital input switches as well.

Testing the MQTT Sparkplug Network

This means I should be publishing Sparkplug messages to my HiveMQ Broker whenever a change is detected in any one of the metrics. But before I connect my Ignition Platform to the MQTT Broker, I need to test if I am indeed publishing Sparkplug messages.

To do that, I’m going to use an MQTT client software that is compatible with Sparkplug, called MQTT.fx.

I’m already connected to my HiveMQ Broker using MQTT.fx, so I’ll subscribe to receive all Sparkplug messages that are being pushed to my MQTT broker.Subscribing to receive all Sparkplug messages that are being pushed to my MQTT brokerWhen I move my potentiometer, the value changes.When I move my potentiometer, the value changesAnd when I push one of the buttons, it updates with changes.when I push one of the buttons, it updates with changesNext, set up the Ignition platform to connect to my HiveMQ Broker, receive the Sparkplug messages, and then visualise them.

Auto-Discovery and Visualisation Using Ignition Platform

I open my Ignition SCADA platform running on my PC to subscribe to my HiveMQ Broker, receive the Sparkplug messages that are being published from the PLCnext Edge Gateway and visualise the information.

My Ignition Gateway is running at localhost, port 8088Ignition GatewayNext I configure an MQTT module from Cirrus Link called MQTT Engine.

By simply inputting my HiveMQ Cloud Broker details, the MQTT Engine will connect to the broker, automatically discover the data being published by my PLCnext Edge Gateway, and pull all the metrics in their respective folder structures.

Going to my MQTT Engine, I’ll select config here.

Scroll down, and click on Settings, under MQTT Engine.

Configure an MQTT module from Cirrus Link called MQTT EngineMy MQTT Engine is already enabled.

Next, I’ll go to my servers tab.my servers tab on IgnitionAnd this is where I need to put my HiveMQ Cloud MQTT Broker details.

I’ll create a new MQTT server.create a new MQTT serverI fill in my HiveMQ Broker details and click on Create MQTT Server.

Now, my MQTT Engine is configured and will automatically pull all the tags that are currently being published to my HiveMQ Broker.MQTT Engine is configuredTo views those tags, I need to open Ignition Designer software.

I’ll open my Ignition Designer Software and then go to my tag browser and select MQTT Engine.

If I look under my Edge Nodes here, I’ll see that MyDemoRoom GroupID which I created on my PLCnext gateway is already appearing.MyDemoRoom GroupID created on PLCnext gatewayIf I expand that, I can see PLCnextStarterKit, which is the EdgeNodeID that I assigned to my PLCnext Edge Gateway.PLCnextStarterKit, which is the EdgeNodeID that is assigned to my PLCnext Edge GatewayAnd if I expand that I can see my Client or DeviceID, and under that are all of my metrics that I’m publishing from my PLCnext Sparkplug Edge of Node.publishing from my PLCnext Sparkplug Edge of Node

All of this hierarchical information is retrieved by simply providing the MQTT Broker address, and nothing else. And Ignition gateway is able to automatically discover all of this information through Sparkplug.

If I move my potentiometer, the value changes in real-time.If I move my potentiometer, the value changes in real-timeFrom here I can start building powerful graphics to visualise this information using Ignition’s Perspective module.

To demonstrate that,I’ll create a sample page.create a sample pageDragging my voltage metric onto the canvas, I’ll select a slider control to visualise the metric. Then I’ll adjust the scaling accordingly to see my slider move as I adjust the potentiometer on my PLCnext StarterKit.

Next I’ll add my digital switches.adding the digital switchesThey are updated with changes.

Conclusion

I have successfully built a Sparkplug solution that allows the Ignition SCADA platform to automatically discover data that is being generated by a PLCnext Controller and published to a centralized HiveMQ Broker in the cloud.

I hope this demonstration about real world MQTT for Industry 4.0 was helpful. You can learn more about Sparkplug using our Sparkplug Essentials Guide.

Check out the video below that provides the summary of this blog

Begin your MQTT journey with no risks attached. Get a complete MQTT platform offering unlimited connections, 99.95% uptime SLA, 24/7 support, data streaming integrations, and more. Sign up for a free 15-day trial.

Try HiveMQ Cloud Starter

Kudzai Manditereza

Kudzai is a tech influencer and electronic engineer based in Germany. As a Sr. Industry Solutions Advocate at HiveMQ, he helps developers and architects adopt MQTT and HiveMQ for their IIoT projects. Kudzai runs a popular YouTube channel focused on IIoT and Smart Manufacturing technologies and he has been recognized as one of the Top 100 global influencers talking about Industry 4.0 online.

  • Kudzai Manditereza on LinkedIn
  • Contact Kudzai Manditereza via e-mail
HiveMQ logo
Review HiveMQ on G2