This control scenario is simplistic in nature, but can be more complicated to integrate. We’ll be looking at incorporating MQTT into an existing project.

The idea being that we can publish topics and data to an industrial PC that will collect and store the aggregated data.

There will be two types of data:

  • Cyclic – Collected even if the value hasn’t changed
  • Alarm – Only collected on an edge detection of the event monitored

We’ll be looking to retain data too, such that if the connection is lost, it can be re-collected later.

PLC Project

For this project, we’ll be using the September 2023 Solution as our base project. This is because it already has a setup for multiple PLCs and we can explore each PLC publishing their own data, or the supervisory publishing on their behalf. This gives us a good way to explore the differences and how they’re set up

Download Project

You can download the September 2023 Solution below:

What Data Are We Looking For?

The Supervisory PLC will be responsible for sending MQTT data on behalf of the Turbines. We’re looking to send the Receive_Data, which is part of the Turbine_Data.

  • Load – Real
  • RPM – Real
  • Temperature – Real
  • kWh – Real
  • Status – Byte

These will be sent to the Broker and then picked up by the Windows client.

📝MQTT Is New To Me Too

This is probably the first Do & Grow scenario where I don’t really know everything there is to know about the topic either. So I’ll be really doing this along side you all at the same time!

Be sure to ask for help along the way if you need it. A new channel has been set up in Discord for this scenario too.

Getting Started

Before we can jump in and start modifying the project to include MQTT, we need to get the MQTT library and import the blocks into our Project Library. At the same time, we’ll need a Mosquitto install and an MQTT Client so we can interact with the data

MQTT Library In TIA Portal

Below is a video that shows how I installed MQTT from the LMQTT Library. Here’s the link to the download page (you may need to sign in with Siemens’ website in order to download):

https://support.industry.siemens.com/cs/document/109780503/libraries-for-communication-for-simatic-controllers

Note: Video quality is set to automatic by default. You can change this to HD (1080p) by using the options in the bottom right of the video if required

MQTT Broker – Mosquitto

In order for our PLC to communicate to something else, we need to communicate with a “Broker”. The PLC does not have this built in, so we need to install one.

For the ease of this control scenario, we’ll only communicate locally, but the same would apply to a remote broker in most cases

We’re going to use “Mosquitto” as it’s very common and runs easily on Windows.

You can download the broker here:

https://mosquitto.org/download/

Once installed, you can follow the below steps to get it up and running:

  1. Open an administrator command prompt
    • Right click on CMD and choose “Run as administrator”
  2. type net start mosquitto
    • If done correctly, you’ll see this:

At this point, the mosquitto broker is running.

MQTT Client On Windows

In order to see what the PLC is sending, we need an alternative client that visualizes the topics / data that is being sent.

I’m using MQTT Explorer as it’s free and simple to use, you can download it here:

https://mqtt-explorer.com/

Once installed, open it up and create a new connection by clicking the “+” symbol in the top left. Configure your connection to look like this:

Remember to click SAVE, otherwise you’ll have to repeat this step every time you open the explorer.

With this step complete, you now have the following setup:

PLC Client –> Mosquitto Broker –> Windows Client

The next tip will help explain how the Client in TIA Portal is used, but you should drop one into a project, read the help files and see if you can get data across the MQTT structure and into the Windows client!

Leave a Reply