SubscribeWithQualityOfServiceLevel

TwinCAT TIA
Network MQTT Client ActiveClients One client

ns=2;s=DEPRAG Smart/Network/MQTT/ActiveClients/0/SubscribeWithQualityOfServiceLevel

Subscribes to an MQTT topic with QoS from the MQTT broker.

Parameters:

    QualityOfServiceLevel
    Configures the Quality of Service level of the transmission:
    AtMostOnce(0): The message is published exactly once and no acknowledgement of receipt from the broker is awaited.
    AtLeastOnce(1): The message is sent until the client receives an acknowledgement from the MQTT broker. This ensures that the message has arrived at the receiver at least once.
    ExactlyOnce(2): The message is transmitted exactly once from the client to the broker.

Returns:

Examples:

In addition to the parameters already explained, the following variables must be created / transferred for the implementation in TwinCAT 3:

Beckhoff parameter:

    bMqttSubscribeWithQualityOfServiceLevel
    A boolean variable that can be used to trigger the execution of the SubscribeWithQualityOfServiceLevel command.
    OutputDataMqttSubscribeWithQualityOfServiceLevel
    An instance of the ST_VoidOutputData structure into which the return value of the SubscribeWithQualityOfServiceLevel method is written.
    hrMqttSubscribeWithQualityOfServiceLevel
    This can be used to monitor the execution of the command. Error codes have the type HRESULT.
    fbMqtt
    An instance of the "FB_Mqtt" function block supplied with the DEPRAG Smart library.
    sTopic
    A string(255) variable that specifies the topic to subscribe to.
    QualityOfServiceLevel
    An enum of type "MqttQualityOfServiceLevel" which specifies the Quality of Service level of the transmission.
    sClientId
    A String(255) variable that specifies the client that should execute the command.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
   bMqttSubscribeWithQualityOfServiceLevel    : BOOL;
   OutputDataMqttSubscribeWithQualityOfServiceLevel : ST_VoidOutputData;
   hrMqttSubscribeWithQualityOfServiceLevel   : HRESULT;

   fbMqtt  : FB_Mqtt;
END_VAR

hrMqttSubscribeWithQualityOfServiceLevel := fbMqtt.SubscribeWithQualityOfServiceLevel(
     bExecute    := bMqttSubscribeWithQualityOfServiceLevel, 
     ConnectionHandle  := depragSmartConnection.ConnectionHandle, 
     sTopic     := 'testSmart/test', 
     QualityOfServiceLevel := MqttQualityOfServiceLevel.ExactlyOnce, 
     sClientId    := '0', 
     OutputData    => OutputDataMqttSubscribeFullyParameterized);
IF hrMqttSubscribeWithQualityOfServiceLevel <> S_FALSE THEN 
    bMqttSubscribeWithQualityOfServiceLevel := FALSE;
END_IF
                                                    

For examples and explanations regarding the calls of nodes via Siemens TIA Portal please refer to the sub-menu "Siemens TIA Portal" in section "Getting Started".