Structure of MQTT Clients
Implement the MQTT communication part in mobile apps and thing clients with external components such as open source libraries. The Kii SDK is designed to provide MQTT communication outside the SDK. Exceptionally, the Thing-IF SDK includes the communication control logic for the MQTT protocol.
Please refer to the list of available libraries by MQTT.org.
See the below examples of MQTT client implementation. These are standard structures for communication with Kii Cloud.
- Using Push Notification with Web App
- Using Thing-IF SDK/Thing SDK Embedded
- Using Push Notification on Node.js
- Using MQTT Only with Thing Client
Using Push Notification with Web App
This case uses MQTT over WebSocket to make use of push notification.
Use the Kii Cloud SDK or Thing-IF SDK for JavaScript to send requests to Kii Cloud. HTTPS communication is processed inside the SDK.
Usually, the SDK can cover all the communication but you can directly call REST APIs via HTTPS if necessary.
Using Push Notification on Node.js
This case uses MQTT over the TCP socket to make use of push notification.
Use the Kii Cloud SDK for JavaScript to send requests to Kii Cloud. HTTPS communication is processed inside the SDK.
Usually, the SDK can cover all the communication but you can directly call REST APIs via HTTPS if necessary.
While Node.js runs in various environments, it is especially effective for thing implementation. Like the case with the web app, you can implement push notification over WebSocket. However, it would be simpler to use the TCP socket for communication outside the web browser.
Using Thing-IF SDK/Thing SDK Embedded
This case uses MQTT over the TCP socket to leverage push notification technology in receiving Thing-IF commands. MQTT over the TCP socket is also used in the implementation where the Thing SDK Embedded directly uses push notification.
Use the Thing-IF SDK/Thing SDK Embedded to send requests to Kii Cloud. HTTPS communication is processed inside the SDK.
The Thing-IF SDK/Thing SDK Embedded include the functionality of MQTT client. So, you do not need to incorporate any external library for MQTT communication. However, your app needs to provide a process of network connection for portability (Note that such a process is omitted in the figure).
The Thing SDK Embedded used inside the Thing-IF SDK can directly call REST APIs. So, basically, your app does not need to call REST APIs without using the SDK.
Using MQTT Only with Thing Client
This case uses MQTT over the TCP socket for calling APIs as well as providing push notification.
This structure is employed when you want to develop things not using HTTPS but MQTT only. Call APIs directly instead of using any SDK as no SDK supports this method.
Distinguish push notifications and responses from Kii Cloud based on MQTT commands and MQTT topic names.