IotMqttSampleBoschIoT

Sample for MQTT communication with the Bosch IoT Hub

This sample shows the communication with the Bosch IoT Hub, which is part of the Bosch IoT Suite. This message broker requires the use of TLS and user name/password authentication.

IotMqttSampleBoschIoT 1:

Initial setup of the Bosch IoT Hub

Information on the initial setup of the Bosch IoT Hub can be found in the official Bosch IoT Suite documentation.

IotMqttSampleBoschIoT 2:

Topic structure

The topic structure for sending and receiving messages is predefined by the message broker of the Bosch IoT Suite.

In this sample messages are sent to the Bosch IoT Hub and received from it. Since this sample is essentially based on the sample IotMqttSampleUsingQueue, only the parts that are relevant for establishing a connection to the Bosch IoT Hub are explained in this section.

Parameters for establishing a connection

The following code snippet shows the parameters required for establishing a connection to the Bosch IoT Hub. 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\BoschIotHub.crt';
  fbMqttClient.sHostName:= 'mqtt.bosch-iot-hub.com';
  fbMqttClient.nHostPort:= 8883;
  fbMqttClient.sClientId:= 'CX-12345';
  fbMqttClient.sUserName:= 'com.someName_CX@t42c3e689c5c64c34b13084b9504ed3c8_hub';
  fbMqttClient.sUserPassword:= 'somePassword';
END_IF

The parameters required for authentication can be generated on the Bosch IoT platform.