com.ibm.wiotp.sdk.device

Class DeviceClient

  • All Implemented Interfaces:
    org.eclipse.paho.client.mqttv3.MqttCallback, org.eclipse.paho.client.mqttv3.MqttCallbackExtended
    Direct Known Subclasses:
    GatewayClient, ManagedDevice


    public class DeviceClient
    extends AbstractClient
    implements org.eclipse.paho.client.mqttv3.MqttCallbackExtended
    A client, used by device, that handles connections with the IBM Watson IoT Platform.
    This is a derived class from AbstractClient and can be used by embedded devices to handle connections with IBM Watson IoT Platform.
    • Constructor Detail

      • DeviceClient

        public DeviceClient(DeviceConfig config)
                     throws Exception
        Create a device client for the IBM Watson IoT Platform.
        Parameters:
        config - Configuration object for the client
        Throws:
        Exception - When there is a failure in parsing the properties passed
    • Method Detail

      • connect

        public void connect()
                     throws org.eclipse.paho.client.mqttv3.MqttException,
                            KeyManagementException,
                            NoSuchAlgorithmException

        Connects the application to IBM Watson IoT Platform and retries when there is an exception.
        This method does not retry when the following exceptions occur.

        • MqttSecurityException - One or more credentials are wrong
        • UnKnownHostException - Host doesn't exist. For example, a wrong organization name is used to connect.
        Overrides:
        connect in class AbstractClient
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException - One or more credentials are wrong
        NoSuchAlgorithmException - TLS issues
        KeyManagementException - TLS issues
      • publishEvent

        public boolean publishEvent(String eventId,
                                    Object data,
                                    int qos)
        Publish data to the IBM Watson IoT Platform.
        Parameters:
        eventId - object of String which denotes event
        data - Payload data
        qos - Quality of Service, in int - can have values 0,1,2
        Returns:
        Whether the send was successful.
      • publishEvent

        public boolean publishEvent(String eventId,
                                    Object data)
      • connectionLost

        public void connectionLost(Throwable e)
        Simply log error when connection is lost
        Specified by:
        connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallback
      • deliveryComplete

        public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
        A completed deliver does not guarantee that the message is received by the service because devices send messages with Quality of Service (QoS) 0.
        The message count represents the number of messages that were sent by the device without an error on from the perspective of the device.
        Specified by:
        deliveryComplete in interface org.eclipse.paho.client.mqttv3.MqttCallback
        Parameters:
        token - MQTT delivery token
      • messageArrived

        public void messageArrived(String topic,
                                   org.eclipse.paho.client.mqttv3.MqttMessage msg)
        The Device client does not currently support subscriptions.
        Specified by:
        messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallback
      • connectComplete

        public void connectComplete(boolean reconnect,
                                    String serverURI)
        Specified by:
        connectComplete in interface org.eclipse.paho.client.mqttv3.MqttCallbackExtended
      • registerCodec

        public void registerCodec(MessageCodec codec)
      • registerCommandCallback

        public void registerCommandCallback(CommandCallback callback)

Copyright © 2019. All rights reserved.