Re-parameterization

In certain cases, it may be necessary to re-parameterize the HTTP client during operation by means of an Online Change. The 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 new parameterization: replacement of a token that is about to expire, certificates that need to be renewed or a changed IP address of the HTTP server. The following section describes the procedure for re-parameterization of an HTTP client that has already been parameterized.

For cyclic background communication of an HTTP client function block with the TwinCAT driver, the Execute method must be called cyclically in the background (see FB_IotHttpClient). When a program is started, calling this method first sets the parameters of the HTTP client instance, after which it is possible to send HTTP requests. The variable bConfigured is able to detect completion of this parameterization. The HTTP client is fully configured once the variable has the value TRUE.

To carry out a new parameterization, the call of the Execute method must be suspended and the Disconnect method must be called. It is important to ensure that no more HTTP requests are sent at the time of the call. By calling the Disconnect method bConfigured is set to FALSE. The parameters are then reset and the Execute method is called again as usual. The following code snippet shows a simple re-parameterization using a trigger.

IF bReset THEN
    fbHttpClient.Disconnect();
    IF fbHttpClient.bConfigured=FALSE THEN
        fbHttpClient.sHostName:='postman-echo.com';
        fbHttpClient.stTLS.sCA:='C:\TwinCAT\3.1\Config\Certificates\caCERT.cer';
        bReset:=FALSE;
    END_IF
ELSE
    fbHttpClient.Execute();
END_IF

The trigger variable bReset suspends the call of the Execute method and calls the Disconnect method. Once bConfigured is set to FALSE on the HTTP client function block, the host name and CA certificate parameters are reset. bReset is then reset and the Excute method is called again.