Start

TwinCAT TIA
Network MQTT Client ActiveClients One client

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

Parameterizes the MQTT client and establishes a connection to the specified MQTT broker.

Parameters:

    PendingMessagesOverflowStrategy
    Sets the procedure when the number of messages to be sent is greater than the buffer:
    DropOldestQueuedMessage(0): Drop oldest message
    DropNewMessage(1): Drop newest message
    ClientName
    Identification of the MQTT client at the broker.
    CleanSession
    Tells the broker whether messages are cached for this client when the connection is lost. The messages are transmitted when the connection is established.
    KeepAlivePeriodInSeconds
    Time interval in seconds after which it is checked whether the connection with the broker still exists.
    WillMessage
    Sets the last will message for the MQTT client. This message is communicated by the broker to all other MQTT clients when the MQTT client terminates.
    WillTopic
    Sets the last will topic for the MQTT client. This message is communicated by the broker to all other MQTT clients when the MQTT client terminates.
    WillQualityOfService
    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:

    Start
    A variable of type OpcMethodReturnValueVoid.

Examples:

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

Beckhoff parameter:

    bMqttStart
    A boolean variable that can be used to trigger the execution of the Start command.
    OutputDataMqttStart
    An instance of the ST_VoidOutputData structure into which the return value of the Start method is written.
    hrMqttStart
    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.
    PendingMessagesOverflowStrategy
    An enum of type "MqttPendingMessagesOverflowStrategy" which specifies how to proceed if the number of messages to be sent is larger than the buffer.
    sClientName
    A string(255) variable representing the identification of the MQTT client at the broker.
    bCleanSession
    A boolean variable that determines whether the broker caches messages transmitted by other clients when the MQTT client loses connection (parameter = False) or caches them and delivers them later.
    ProtocolVersion
    An enum of type "MqttProtocolVersionSmart" which specifies the MQTT protocol version to use.
    nKeepAlivePeriodInSeconds
    A DINT variable that defines the time interval in seconds after which an IsAlive message should be sent to the broker.
    sWillMessage
    A String(255) variable representing the Last Will Message for the MQTT client.
    sWillTopic
    A String(255) variable representing the Last Will Topic for the MQTT client.
    WillQualityOfService
    An enum of type "MqttQualityOfServiceLevel" which specifies the Quality of Service level of the transmission.
    nWillDelayIntervalInSeconds
    A DINT variable that specifies the amount of time in seconds that the broker waits after a connection loss before sending the Last Will Message.
    bIgnoreCertificateChainErrors
    A boolean variable that specifies whether to ignore errors in the certificate chain.
    bIgnoreCertificateRevocationErrors
    A boolean variable that specifies whether to ignore errors from the certificate revocation list.
    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
   bMqttStart           : BOOL;
   OutputDataMqttStart         : ST_VoidOutputData;
   hrMqttStart           : HRESULT;

   fbMqtt  : FB_Mqtt;
END_VAR

hrMqttStart := fbMqtt.Start(
     bExecute       := bMqttStart, 
     ConnectionHandle     := depragSmartConnection.ConnectionHandle, 
     PendingMessagesOverflowStrategy  := MqttPendingMessagesOverflowStrategy.DropOldestQueuedMessage, 
     sClientName       := 'SmartTest', 
     bCleanSession      := FALSE, 
     ProtocolVersion      := MqttProtocolVersionSmart.V311, 
     nKeepAlivePeriodInSeconds   := 5, 
     sWillMessage      := 'WillMessage', 
     sWillTopic       := 'WillTopic', 
     WillQualityOfService    := MqttQualityOfServiceLevel.ExactlyOnce, 
     nWillDelayIntervalInSeconds   := 5, 
     bIgnoreCertificateChainErrors  := TRUE, 
     bIgnoreCertificateRevocationErrors := TRUE, 
     sClientId       := '0', 
     OutputData       => OutputDataMqttStart);
IF hrMqttStart <> S_FALSE THEN 
    bMqttStart := 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".