IotMqttSampleTlsCa
Sample for MQTT communication via a secured TLS connection and CA
This sample illustrates the communication with an MQTT broker that requires authentication via TLS and a client certificate. This sample is not available as a separate download, since it is essentially based on the existing samples IotMqttSampleUsingQueue and in particular IotMqttSampleAwsIoT. The latter demonstrates the application of client certificates with TF6701 and can be used in the same way for all other MQTT brokers.
Parameters for establishing a connection
The following code snippet shows the parameters required for establishing a TLS connection to an MQTT broker via client certificate. The parameters are essentially static parameters. These can also be specified in the declaration part during instantiation of the MQTT client.
IF bSetParameter THEN
bSetParameter := FALSE;
fbMqttClient.stTLS.sCA := 'c:\TwinCAT\3.1\Config\Certificates\rootCa.pem';
fbMqttClient.stTLS.sCert := 'c:\TwinCAT\3.1\Config\Certificates\clientCert.pem.crt';
fbMqttClient.stTLS.sKeyFile := 'c:\TwinCAT\3.1\Config\Certificates\clientPrivKey.pem.key';
END_IF
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4022.0 | IPC or CX (x86, x64, ARM) | Tc3_IotBase, |