First, the application initializes and starts the CMSIS-RTOS v2 based real-time operating system. Then, it initializes and prepares the network stack which should be active at that point.
Note: The MQTT client in this case uses TLS sockets (for a secure connection) through the ::Security:mbed TLS interface. The latter also uses the ::IoT Utility:Socket (API) for underlying TCP sockets or the native interface in case of the network component of MDK-Professional.
The MQTT client is then used through its API: MQTTClient.h, MQTTPlatform.h, and MQTTPacket.h:
- The client connects to the server on socket level by calling the functions NetworkInit and NetworkConnectTLS (for a secure connection) (from MQTTPlatform.h). The CA certificate for server verification can be provided and optionally a client certificate and private key for client authentication (if requested by the server) (refer to the user code template ::IoT Client:MQTTClient-C:Certificates).
- Provide a private key for the Jason Web Tokens (JWT) (template ::IoT Client:Google:Device Private Key).
- The JWT is generated with the function google_iot_jwt (from google_iot.h)
- The MQTT client connects on MQTT level using MQTTClientInit and MQTTConnect (MQTTClient.h), using the GOOGLE_IOT_CLIENT_ID macro for the client ID and the JWT as the password.
- The MQTT client exchanges messages using MQTTPublish and MQTTSubscribe (MQTTClient.h)
- Disconnect the MQTT from the server on socket level by calling NetworkDisconnect (MQTTPlatform.h)
The user code template ::IoT Client:Google:Simple Demo provides a starting point for your own implementations. A step-by-step guide is available in the software pack’s Doc folder: Google_IoT_MDK.html.
The Google IoT cloud defines specific topics. More information is available here:
The following MDK-Packs provide the basic building blocks that are required to connect to the Google Cloud IoT Core. These software packs are available from the Pack Installer: