com.ibm.wiotp.sdk.gateway

Class GatewayClient

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


    public class GatewayClient
    extends DeviceClient
    implements org.eclipse.paho.client.mqttv3.MqttCallbackExtended
    A client, used by Gateway, that simplifies the Gateway interactions with IBM Watson IoT Platform.

    Gateways are a specialized class of devices in Watson IoT Platform which serve as access points to the Watson IoT Platform for other devices. Gateway devices have additional permission when compared to regular devices and can perform the following functions:

    • Register new devices to Watson IoT Platform
    • Send and receive its own sensor data like a directly connected device,
    • Send and receive data on behalf of the devices connected to it
    • Run a device management agent, so that it can be managed, also manage the devices connected to it

    Refer to the documentation for more information about the Gateway support in Watson IoT Platform.

    This is a derived class from AbstractClient.
    • Constructor Detail

      • GatewayClient

        public GatewayClient(GatewayConfig config)
                      throws Exception

        Create a Gateway client for the IBM Watson IoT Platform using the properties file passed. The properties must have the following definitions,

        • org - Your organization ID.
        • type - The type of your Gateway device.
        • id - The ID of your Gateway.
        • auth-method - Method of authentication (The only value currently supported is "token").
        • auth-token - API key token.
        Parameters:
        config - Configuration object for the gateway client with the Watson Internet of Things Platform module.
        Throws:
        Exception - Failure in parsing the properties passed
    • Method Detail

      • publishDeviceEvent

        public boolean publishDeviceEvent(String deviceType,
                                          String deviceId,
                                          String event,
                                          Object data)
      • publishDeviceEvent

        public boolean publishDeviceEvent(String typeId,
                                          String deviceId,
                                          String eventId,
                                          Object data,
                                          int qos)
        Publish an event on the behalf of a device to the IBM Watson IoT Platform.
        Parameters:
        typeId - object of String which denotes deviceType
        deviceId - object of String which denotes deviceId
        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.
      • subscribeToDeviceCommands

        public void subscribeToDeviceCommands(String tpyeId,
                                              String deviceId,
                                              String commandId,
                                              String format,
                                              int qos)
        Subscribe to device commands, on the behalf of a device, to the IBM Watson IoT Platform.
        Parameters:
        tpyeId - object of String which denotes deviceType
        deviceId - object of String which denotes deviceId
        commandId - object of String which denotes command
        format - object of String which denotes format, typical example of format could be json
        qos - Quality of Service, in int - can have values 0,1,2
      • unsubscribeFromDeviceCommands

        public void unsubscribeFromDeviceCommands(String typeId,
                                                  String deviceId,
                                                  String commandId)
        Unsubscribe from device commands, on the behalf of a device, from the IBM Watson IoT Platform.
        Parameters:
        typeId - object of String which denotes deviceType
        deviceId - object of String which denotes deviceId
        commandId - object of String which denotes command name
      • messageArrived

        public void messageArrived(String topic,
                                   org.eclipse.paho.client.mqttv3.MqttMessage msg)

        This method is called by the MQTT library when a message(command) is sent by the IBM Watson IoT Platform.

        The message(command) will be processed by this class and corresponding callback method will be called if registered.
        Specified by:
        messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallback
        Overrides:
        messageArrived in class DeviceClient

Copyright © 2019. All rights reserved.