TsgcWSPClient_MQTT › Properties › MQTTVersion
Selects the MQTT protocol level advertised in the CONNECT packet (3.1.1 or 5.0).
property MQTTVersion: TwsMQTTVersion read FMQTTVersion write SetMQTTVersion;
mqtt311
Accepts mqtt311 (protocol level 4, the default and most widely supported version) or mqtt5 (protocol level 5). MQTT 5.0 is not wire-compatible with 3.1.1: it adds reason codes, user properties, session expiry, topic aliases, shared subscriptions, enhanced authentication and server-initiated DISCONNECT. When MQTTVersion = mqtt311, any values assigned to ConnectProperties, LastWillTestament.WillProperties and the various *Properties arguments on Publish, Subscribe, Unsubscribe, Disconnect and Auth are silently ignored. Set MQTTVersion before activating the connection; changing it while connected has no effect until the next CONNECT.
MQTT.MQTTVersion := mqtt5;
MQTT.ConnectProperties.Enabled := True;
MQTT.ConnectProperties.SessionExpiryInterval := 300;