Last will

The LastWill is a message sent by the broker to all clients subscribed to the matching topic in case of an irregular connection failure. If the MQTT client in the PLC loses the connection to the broker and a LastWill was stored when the connection was established, this LastWill is communicated by the broker without the client having to worry about it.

In the case of a planned disconnect, the LastWill is not necessarily transmitted according to the specification. From the PLC programmer's point of view, he can decide whether he wants to publish the LastWill before calling the disconnect. For this purpose, the LastWill message is published again on the LastWill topic. This is necessary because the broker would not publish the LastWill message due to the regular disconnection.

In the event of a TwinCAT context change and a resulting restart of the MQTT communication, the IoT driver sends the previously specified LastWill to the broker, because at this moment there is no longer any possibility from the PLC. If no LastWill was defined when the connection was established, no message will be transmitted before the disconnect.