Re-parameterization
In certain cases, it may be necessary to re-parameterize the MQTT client during operation by means of an online change. This new parameterization can either take place automatically in the program sequence or be triggered manually if required. This depends on the implementation.
Example use cases for a re-parameterization: replacement of a token that is about to expire, certificates that need to be renewed or a changed IP address of the MQTT broker. The following section describes the procedure for re-parameterization of a connected MQTT client.
In order for the TwinCAT MQTT client to be connected to a message broker, the Execute method must be called cyclically in the background (see FB_IotMqttClient). When the program starts, the parameterization of the MQTT client instance is carried out first by calling this method, after which a connection to the broker is established. In order to carry out a re-parameterization, the call of the Execute method must be negated, the parameters must then be reset and the call must then take place again as usual. The following code snippet shows a simple re-parameterization using a trigger.
fbMqttClient.Execute(bConnect);
IF bReset THEN
bConnect:=FALSE;
fbMqttClient.ClientId:= 'MyTcMqttClient35';
fbMqttClient.sHostName:= '192.168.35.35';
bReset:=FALSE;
ELSE
bConnect:=TRUE;
END_IF
The call of the Execute method is negated by the trigger variable bReset, so that the parameters for the client ID and the host name can be reset afterwards. Once the trigger variable is set to FALSE again, the execute method is called cyclically again.