Quick Start

This section describes how to get started quickly with the TC3 IoT Data Agent.

The communication scenario is a typical use case for the Data Agent: Variables from a southbound device (TwinCAT PLC runtime) are sampled and published to a northbound service (MQTT Message Broker). In this example, the message broker is running on the same computer as the PLC runtime.

To set up this scenario, the following steps are required. All steps are performed on the same computer.

Install the software

  1. Install TF6720 IoT Data Agent as described in the Installation section.
  2. Install Mosquitto MQTT Message Broker with its default setup settings. The Message Broker can be installed anywhere and is connected to via its hostname or IP address.
  3. Open a Windows Console, navigate to the installation directory of the Mosquitto MQTT Message Broker (typically C:\Program Files (x86)\mosquitto) and start the Broker in verbose mode by executing the following command: mosquitto.exe -v

Mosquitto MQTT Message Broker

The Mosquitto MQTT Message Broker can be downloaded from www.mosquitto.org. Make sure to follow any installation instructions provided by the Mosquitto installer.

Mosquitto startup

By default, the Mosquitto MQTT Message Broker is installed as a Windows service. You can also start the mosquitto.exe from a command line and specify parameters like "-v" for verbose output. If you want to start the broker from a command line, make sure that the Mosquitto Windows service is not running.

Prepare the PLC program

Set up a TwinCAT 3 PLC project and activate trial licenses for TC1200 (PLC) and TF6720 (TC3 IoT Data Agent). In this sample the PLC program should include the following variables:

PROGRAM MAIN
VAR
    nCounter1 : INT;
    nCounter2 : LREAL;
END_VAR

These two variables should be incremented cyclically. Add the following implementation code for the PLC program:

nCounter1 := nCounter1 + 1;
nCounter2 := nCounter2 + 0.1;

Activate the project and start TwinCAT into run mode. Make sure that the PLC program is running by logging in.

Configure TwinCAT IoT Data Agent

1. Start the TwinCAT IoT Data Agent configurator, either via its link on the Windows start menu or via the system tray application (see Configurator).
2. Follow the step-by-step instructions below to create a Data Agent configuration. As an alternative you can also open the configuration file "Sample_QuickStart.xml", which can be found in the Data Agent installation directory, and directly move on with step (m).
3. Start a new configuration by clicking on the New icon in the configurator toolbar.
4. In the topology view, right-click a blank area and select Add Gate (ADS).
5. Select the new gate and make sure that the local AmsNetId and ADS port 851 are selected in the properties window
6. In the topology view, right-click the new gate and select Add Channel (Subscriber).
7. Select the new channel and make sure that sampling mode “cyclic” and cycle time “1000” are selected in the properties window.
8. Open the target browser and navigate to your local PLC runtime (port 851).
9. Select the variables “nCounter1” and “nCounter2” and drag them to the subscriber channel in the topology view.
10. In the topology view, right-click a blank area and select Add Gate (MQTT).
11. Select the new gate and make sure that the URL is set to 127.0.0.1 and Port 1883 is being used.
12. In the topology view, right-click the new gate and select Add Channel (Publisher).
13. Select the new channel and make sure that the sampling mode is set to “cyclic”. Set the cycle time to “1000” and the formatter to “TwinCAT JSON”. The MQTT topic can be set to a topic of your choice, e.g. “TestTopic”.
14. Hold the CTRL key and drag the subscriber channel to the publisher channel in order to create a mapping between the source and destination symbols. Note that the destination symbols are automatically created.
15. Activate the configuration by clicking on the Activate Configuration button in the toolbar.

Quick Start 1:

Display the published messages

Open a command line window and navigate to the installation directory of the Mosquitto MQTT Message Broker (typically "C:\Program Files\mosquitto" or "C:\Program Files (x86)\mosquitto"). Start the Mosquitto Subscriber tool by executing the following command: mosquitto_sub.exe -t TestTopic.

Quick Start 2:

The Mosquitto Subscriber tool will now receive the messages that are published from the TwinCAT IoT Data Agent.

Quick Start 3: