Response

Response 1:

This method is called once to send a response to a request.

Possible errors are output at the outputs bError and hrErrorCode of the function block instance.

Syntax

METHOD Response : BOOL
VAR_IN_OUT
    sResponseTopic       : STRING; // topic string (UTF-8) with any length (attend that MQTT topics are case sensitive)
END_VAR
VAR_INPUT
    pPayload            : PVOID;
    nPayloadSize        : UDINT;
    eQoS                : TcIotMqttQos; // quality of service between the publishing client and the broker
    bRetain             : BOOL; // if TRUE the broker stores the message in order to send it to new subscribers
    bQueue              : BOOL; // for future extension
    pProps              : POINTER TO MqttPublishProperties;
    pCorrelationData    : POINTER TO BYTE;
    nCorrelationDataSize: UINT;
END_VAR

Response 2: Return value

Name

Type

Description

Response

BOOL

The method returns the return value TRUE if the call was successful.

Response 3: Inputs

Name

Type

Description

pPayload

PVOID

Address for the payload of the MQTT message

nPayloadSize

UDINT

Size of the payload in bytes

eQoS

TcIotMqttQos

"Quality of Service"

bRetain

BOOL

If bRetain is TRUE, the broker stores the message in order to make it available to subsequent subscribers.

bQueue

BOOL

Reserved parameter that can always be given the value FALSE.

pProps

POINTER TO MqttPublishProperties

Pointer to Publish properties to be sent.

The parameter is optional. The FB_IotMqtt5PublishProperties can be used to specify Publish properties.

pCorrelationData

POINTER TO BYTE

Pointer to the CorrelationData to be sent. This can be used to assign a request to a received response in a request/response procedure.

nCorrelationDataSize

UINT

Size of the CorrelationData in bytes

Response 4: Inputs/outputs

Name

Type

Description

sResponseTopic

STRING

Topic on which the response should be sent.

Response 5:

Message payload formatting

Note that the data type and the formatting of the content must be known to the sender and receiver side, particularly when binary information (alignment) or strings (with or without zero termination) are sent.

Response 6:

Strings in UTF-8 format

The variables of type STRING used here are based on the UTF-8 format. This STRING formatting is common for MQTT communication as well as for JSON documents.

In order to be able to receive special characters and texts from a wide range of languages, the character set in the Tc3_IotBase and Tc3_JsonXml libraries is not limited to the typical character set of the data type STRING. Instead, the Unicode character set in UTF-8 format is used in conjunction with the data type STRING.

If the ASCII character set is used, there is no difference between the typical formatting of a STRING and the UTF-8 formatting of a STRING.

Further information on the UTF-8 STRING format and available display and conversion options can be found in the documentation for the Tc2_Utilities PLC library.