IotMqttv5ReqResSample
Sample for the use of MQTTv5 Request/Response
In this sample, the communication to an MQTT broker using MQTTv5 is shown. In particular, the Request/Response mechanism of MQTTv5 is demonstrated. As a prerequisite, the message broker used must support MQTTv5. The basic flow of the sample is as follows:
- There is a PLC project that demonstrates the request function and also receives and evaluates the response from the remote terminal. The project first subscribes to the so-called response topic (on which it expects a response from the remote terminal) and then sends the request, which contains the name of the response topic. Advanced properties of the MQTTv5 message, such as UserProperties or CorrelationData, are also demonstrated here.
- A second PLC project is responsible for receiving the request and sending a corresponding response to the response topic. The MQTT client first subscribes to the topic on which the request is received and prepares the corresponding response when a request is received. The response topic and the extended properties of the MQTTv5 message are extracted from the received message and used for the response.
The following figure once again illustrates the basic flow of communication. More information about individual lines of code can be found directly in the comments of the corresponding sample download.

Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4026.0 | IPC or CX (x86, x64, ARM) | Tc3_IotBase (>= v3.4.2.0), |