MQTT
This sample demonstrates how to set up a publisher and subscriber based on OPC UA Pub/Sub MQTT. The sample solution contains a TwinCAT project that includes the following PLC configuration:
- a PLC project that generates random data and links the data with data sets on the OPC UA RT Device’s publishers.
- a PLC project that stores the data received by subscribers on the OPC UA RT Device.
The I/O configuration includes an OPC UA RT Device with two publishers and two subscribers:
- a publisher that is configured to include a data set with variables. The variables are linked via the process image to the output variables of the first PLC project.
- a publisher that is configured to include a data set without variables. The variables are linked internally via their ADS symbol names to variables in the first PLC project.
- a subscriber that is configured to subscribe to the data published by the first publisher. The input variables are linked with variables from the second PLC project.
- a subscriber that is configured to subscribe to the data published by the second publisher. The input variables are linked with variables from the second PLC project.
![]() | Creation of the subscribers The subscribers have been created automatically based on the Configuration import/export. We highly recommend using this exchange format wherever possible. |
How to start the sample
Please make sure that your system meets the system requirements.
Before you activate the TwinCAT project, please make sure that you have an MQTT Message Broker running locally on the same system. The message broker should listen on port 1883/tcp without any encryption or user authentication. Please note that this is only for demonstration purposes! Please adapt this configuration to your environment. The MQTT settings can be found on the OPC UA RT device.

You can then activate the TwinCAT project and login to the PLC projects to debug the PLC runtime. You should see that the subscriber PLC project receives data (which is published by the other PLC project).