ARTIK Cloud Java/Android SDK now supports MQTT

We are pleased to announce that ARTIK Cloud Java/Android SDK v2.2.0 now supports MQTT, as well as REST and WebSocket. It’s based on the Paho Java MQTT client library


Implementing MQTT functionality in your Java/Android application is easy. Here are the steps:

  1. Create a callback object and implement the callback methods that interest you.
    ArtikCloudMqttCallback callback = new ArtikCloudMqttCallback() {
    public void onFailure(OperationMode opMode, IMqttToken mqttToken, Throwable throwable) {...}
    public void onSuccess(OperationMode opMode, IMqttToken mqttToken) {...}
    public void connectionLost(Throwable cause) {...}
    public void messageArrived(String topic, MqttMessage message) {...}
    public void deliveryComplete(IMqttDeliveryToken token) {...}
    Peek into the source code to learn the details of the callback and parameters.
  2. Construct an MQTT session object using a device ID, device token, and the above callback.
    MqttSession mqttSession = new MqttSession(deviceId, deviceToken, callback);
    The session object forms specific publish and subscribe topics for the given device. See ARTIK Cloud MQTT key concepts for more information.
  3. Connect to ARTIK Cloud.
  4. Subscribe and/or publish as needed. Subscribe to receive Actions targeted to this device:
    Publish a data message for this device:
    String payload    =  ...; // should follow the Manifest of the device type
    int qos = ...; //0, 1, 2
    mqttSession.publish(qos, payload);
  5. Disconnect. 


The test directory of the SDK lists a few integration tests, which are a good introduction to the SDK APIs.

The Java console sample app emulates a smart light communicating to ARTIK Cloud via MQTT. The light can be turned on/off based on Actions from ARTIK Cloud, and sends its latest state (on/off) back to ARTIK Cloud.

Interested in trying out Samsung ARTIK Cloud? Sign up for a developer account and connect devices and services while bypassing silos. We look forward to seeing your IoT solutions!