How to Connect a Smart Factory and Visualize IIoT Data with MQTT Sparkplug

How to Connect a Smart Factory and Visualize IIoT Data with MQTT Sparkplug

author Kudzai Manditereza

Written by Kudzai Manditereza

Category: Real-World MQTT Industry 4.0 MQTT Sparkplug

Published: May 20, 2021

In a smart factory and smart manufacturing ecosystem, integrating and sharing data between heterogeneous systems and services is a huge challenge. One way to overcome this challenge is adopting MQTT Sparkplug open-source IoT specification in the hardware systems and the edge devices. For the reason that, Sparkplug provides MQTT clients the framework to seamlessly integrate industrial data across the entire ecosystem of hardware vendors and application providers, like SCADA, MES, and Historian vendors, within the MQTT infrastructure in a bi-directional and interoperable way.

Through a series of blog posts, we will demonstrate how easy it is to connect different Industry 4.0 products using MQTT Sparkplug B specification and HiveMQ Cloud MQTT broker, and use the generated IIoT data for making quick and better business decisions.

Getting Hands-on with MQTT Sparkplug: A Simple Demonstration

In Part 1 of this series, we will connect an edge device on the plant floor, such as Opto 22 groov Rio using HiveMQ Cloud MQTT broker that supports MQTT Sparkplug B specification and then forward the data to Canary Cloud for analysis. For those unaware, Canary is a process data historian solution that allows you to collect, store and use visual tools to contextualize the data. This data helps in making better business decisions and thus maximizing your operations. Canary offers a wide range of mechanisms to collect data from industrial devices and PLCs such as Opto 22‘s groov Rio, one of which is using the MQTT protocol.

For this demonstration in particular, we will simulate a minimalistic smart factory set up as shown in the image below. Here, we will collect process data, such as temperature, pressure, and liquid level of a Cooling Tower from Opto 22 groov Rio.

Connecting Opto22 groov with HiveMQ Cloud and MQTT Sparkplug
Image 1: Hardware Setup Simulating a Minimalistic Smart Factory

The Power of a MQTT Sparkplug B & Cloud Broker: No Software Installation or Maintenance Required

One of the fun parts of this demonstration is that no software will be installed. HiveMQ Cloud, Opto 22 grov Rio, and Canary Cloud platforms support MQTT Sparkplug B specification. So, if your plant-floor device or PLC supports MQTT Sparkplug B, transferring your plant process data to the Canary Historian is just plug and play. To showcase this possibility, here’s a step-by-step guide on how to go about it.

Step-by-Step Guide to Connecting an Edge Device to MQTT Broker and Visualizing the IIoT Data

HiveMQ Cloud acts as a reliable cloud-based MQTT message broker. It securely receives MQTT messages, which are being published from the plant-floor and forwards them to the Canary Cloud platform, quickly and efficiently. To receive MQTT messages from the MQTT broker, Canary Cloud uses MQTT Collector.

Follow the below steps to set up everything.

Step 1: Setting up HiveMQ Cloud MQTT Broker

To setup your MQTT broker on HiveMQ Cloud, follow the below steps:

  1. Visit HiveMQ MQTT Cloud broker page and sign up for the free version.
HiveMQ Cloud MQTT Broker
  1. Once you sign up, either use your email ID or your GitHub login to log in to your account.
  2. Set up your cluster as soon as you log in for the first time.

Note: While setting up your cluster, you need to set up credentials that your device and Canary MQTT connector will use to connect to the MQTT broker. Refer to the below image. Note that, you can change your credentials as and when required.

HiveMQ Cloud Cluster Details
  1. Once you are logged into the HiveMQ Cloud console, you can see the clusters available for your account and their statuses. For each cluster, you can see your broker’s url address or hostname and the port number.
  2. Click on Manage Cluster.
Creating HiveMQ Cloud Cluster
  1. Get more details about your cluster, as shown below. You can also edit access credentials here.
Creating HiveMQ Cloud Clusters
  1. Once you set up your cluster, an MQTT Broker is automatically provisioned to you.

Step 2: Configuring Opto 22 groov Rio IO Hardware Device

Follow the below steps to configure your Opto 22 groov Rio, so that it starts publishing the liquid level, the temperature level, and the pressure level values of your Cooling Tower as MQTT Sparkplug B messages to your HiveMQ Cloud MQTT broker.

Refer to the hardware setup as shown in Image 1.

  1. Connect an ICTD temperature probe to channel 0 of your Groov Rio IO, for temperature measurement.
  2. Connect a 4-20mA pressure transducer to channel 1 of your Groov Rio IO, for pressure measurement.
  3. Connect a Loadcell’s output millivolt signal to your Groov Rio as an analog input on channel 2 and place a liquid container on top of the Loadcell. This will help in measuring the rise and fall of the liquid level. You can measure it as 0% when the jar is empty and 100% when it is full.
  4. Go back to your browser and start configuring this device to publish these field measurements to the HiveMQ Cloud broker.
  5. Log in to your Opto 22 groov Rio management interface on this IP address.
  6. Select the IO channels as required. For example, select channel 0 to check the temperature, channel 1 to check the pressure, etc.
Configuring Opto22 with MQTT Sparkplug
  1. To check the temperature, select channel 0 and watch the temperature reading. In the below image the temperature currently reads 18.2 When you warm the liquid, the temperature readings will start to rise as shown in the image below.
Setting up Opto 22 groov Rio Channel 0
  1. To check the pressure level, select channel 1 and watch the pressure level reading. When you blow the transducer, the temperature readings will start to rise as shown in the image below.
Setting up Opto 22 groov Rio Channel 1
  1. To check the liquid level in the container, select channel 2 and note the liquid level reading. When you pour some more liquid to the container, the liquid level will start to rise as shown in the image below.
Setting up Opto 22 groov Rio Channel 2

Step 3: Setting up MQTT and Sparkplug B for Publishing

To get the temperature, pressure, and liquid level readings or data to the Canary platform, it is essential that you configure your Opto22 groov Rio to publish cooling tower information to your HiveMQ Cloud broker. To enable MQTT Sparkplug B to start publishing, follow the below configuration steps:

  1. Go to MQTT configuration page in Opto 22 groov Manage and click on Configuration. The Configuration page will open as shown in the image below.
Setting up MQTT Edge Node
  1. In the Configuration page, you can choose to either send MQTT messages as Sparkplug payloads or as string payloads. We chose to send the MQTT messages as Sparkplug payloads.
  2. Specify your Sparkplug Group ID and Edge Node ID. For the purpose of this demo, we have specified Sparkplug Group ID as MyDemoPlant and the Edge Node ID as MyCoolingTower.
  3. Click on Add MQTT Broker as shown in the image below.
Setting up MQTT Broker
  1. Add all the HiveMQ Cloud broker details, such as the Broker URL or hostname, which you copied earlier.
  2. Provide the client a unique and descriptive name.
  3. Enter the username and password details, which you configured on your HiveMQ cluster.
  4. Enable SSL for secure communication.
  5. Specify your Sparkplug Device ID as RioIO.

Step 4: Configuring Canary Historian to Receive MQTT Sparkplug B Messages

To start receiving the messages from MQTT to Canary Cloud, you need to first configure Canary Collector. Follow the below steps:

  1. Configure the MQTT Collector on the Canary platform. To configure the MQTT collector, you need to run the Canary Administrator application. Our Canary system here is already licensed and installed properly. From the table below, you can see that no collectors are enabled or configured yet.
Setting up Canary Administrator and MQTT Collector
  1. Click on the Configuration tab to establish a new Connection Group. A new window will open as shown below. All the components of that Connection Group are automatically populated in the window for you to configure.
  2. Fill in the details to customize your new Connection Group according to your needs. For example, provide the Name, Client ID, etc. Here, we have used HiveMQDemo as our Connection Group name as shown below:
Configuring Canary Historian to Receive
  1. Click on the Servers drop down menu in the left hand window and build out the servers as shown in the image below:
Canary Cloud Server
  1. Copy and paste the unique information to HiveMQ Cloud.
  2. Change the server configuration from public to secure 8883.
  3. Enter the username and password.
  4. Enable SSL/TLS, because we are using 8883.
  5. Save the changes to configure your server.
  6. Click on the Subscriptions drop down menu in the left hand window as shown below:
Getting MQTT Subscriptions on Canary
  1. Modify the Subscription. We’ve already created a wildcard subscription by default. Likewise, you should subscribe and keep the wildcard ID and subscribe to everything that you have access to through the username.
  2. We are going to automatically log all the tags that we find and name the data set that should be within Canary. We’ll call this the HiveMQ data set. Click Apply.
  3. Tell the subscriber where the historian is located. By default, it’s looking for the local host. If you have the MQTT Collector installed locally to Canary Historian, you would leave a local host. In our instance here, we will be sending to a different historian, which would be our historian machine name called canarylive as shown below:
Canary Local Host

Note: You could also put in the IP address. However, we don’t need to do that. Based on our current configuration, we will apply those changes. If you want to create filters on the tags or perform additional optional configuration, use filters and tag properties.

  1. Check the Status on the left hand bottom corner. Now, you will be able to start the session. As shown in the image below, you are now connected, and the system is logging 20 tags. This data is currently coming to the historian.
Canary Connection Group Status
  1. Go to Canary Historian in the Canary Administrator to find your data set. Here, you will find all the tags that you have been logging as shown below.
Canary Cloud Temperature Tags

In the above image, you can find the liquid level, the pressure level, and the temperature tags.

You can also see this data by logging into Axiom and looking at your cloud instance.

Previously, we had created an application. In this application, we were able to see the level of pressure and temperature tags that we are logging from the broker.

Step 5: Visualizing Smart Factory Data on Canary Cloud

Once you have finished configuring Canary to get the data from MQTT, you can use Axiom to start visualizing your data.

Follow the below steps to create a dashboard for visualization:

  1. Open your browser and type in the name of your server.
  2. Build a trending chart for temperature, pressure and liquid level measurements on Axiom as shown below.
Canary Axiom Demo Application
  1. Click on Add Trends and expand your Cooling Tower Asset Model. Now, select the Levels, Temperature and Pressure, as shown below.
Canary Cooling Tower Asset Model
  1. Add a Circular Gauge for measuring the liquid level as shown below.
Canary Circular Gauge
  1. While you have your Canary dashboard open, go to your Opto 22 Rio page.
  2. Start observing the changes to the data instantly in the dashboard, as you pour liquid into the container, blow in to the transducer, or warm the liquid.

Conclusion: Overcome the Current Challenges of Industry 4.0 with MQTT Sparkplug

With this demonstration, you can see how easy it is to collect IIoT data from an edge device in your smart factory setup, send the data as MQTT Sparkplug B messages to HiveMQ Cloud MQTT broker, and forward it to Canary Historian for visualization.

If you want to watch this demonstration in action, watch this video on connecting Opto22, HiveMQ Cloud, and Canary Labs with MQTT and Sparkplug.

We will be covering a series of blog posts showcasing real-world MQTT applications in Industry 4.0. The second part will show How to Send & Receive MQTT Sparkplug B Messages Using Raspberry Pis, Node-RED, and HiveMQ Cloud. Stay tuned!.

Portrait of Kudzai Manditereza

About Kudzai Manditereza

Kudzai is Technology Communicator and Founder at He is currently involved in four efforts: Industry4.0 Research, Educational Videos, Podcast Host, and IIoT Systems Integration. He has a background in Embedded Systems Design, Software Engineering, and Industrial Automation.

author Kudzai Manditereza

About Kudzai Manditereza

Kudzai is an experienced Technology Communicator and Electronic Engineer based in Germany. As a Developer Advocate at HiveMQ, his goals include creating compelling content to help developers and architects adopt MQTT and HiveMQ for their IIoT projects. In addition to his primary job functions, Kudzai runs a popular YouTube channel and Podcast where he teaches and talks about IIoT and Smart Manufacturing technologies. He has since been recognized as one of the Top 100 global influential personas talking about Industry 4.0 online.

Follow Kudzai on LinkedIn

mail icon Contact Kudzai
newer posts Introducing HiveMQ Cloud on Microsoft Azure
How to Use HiveMQ Cloud MQTT Broker with Home Assistant older posts