After you configure the device SDK, connect the gateway device to IoT Platform.


Before you start, make sure that the following operations are performed:

Configure the device SDK for the gateway device

In the SDK package, the DeviceTopoManager file in the java/src/main/java/com/aliyun/iot/api/common/deviceApi directory contains sample code for connecting the gateway device to IoT Platform.

  1. Configure the information about the gateway device for connection.
        private static String regionId = "cn-shanghai";
        private static final String TAG = "TOPO";
        // The information about the gateway device.
        private static String GWproductKey = "a1BxptK***";
        private static String GWdeviceName = "XMtrv3yvftEHAzrTfX1U";
        private static String GWdeviceSecret = "19xJNybifnmgcK057vYhazYK4b64****";
        public static void main(String[] args) {
             * The information about the MQTT connection.
            DeviceTopoManager manager = new DeviceTopoManager();
             * The Java HTTP client of this device supports TSLv1.2.
            System.setProperty("https.protocols", "TLSv2");
  2. Establish a connection.
    public void init() {
            LinkKitInitParams params = new LinkKitInitParams();
             * Specify the parameters for MQTT initialization.
            IoTMqttClientConfig config = new IoTMqttClientConfig();
            config.productKey = GWproductKey;
            config.deviceName = GWdeviceName;
            config.deviceSecret = GWdeviceSecret;
            config.channelHost = GWproductKey + ".iot-as-mqtt." + regionId + "";
             * Specify whether to receive offline messages.
             * The cleanSession field that corresponds to the MQTT connection.
            config.receiveOfflineMsg = false;
            params.mqttClientConfig = config;
            ALog.i(TAG, "mqtt connetcion info=" + params);
             * Configure the initialization and pass in the certificate information about the device.
            DeviceInfo deviceInfo = new DeviceInfo();
            deviceInfo.productKey = GWproductKey;
            deviceInfo.deviceName = GWdeviceName;
            deviceInfo.deviceSecret = GWdeviceSecret;
            params.deviceInfo = deviceInfo;
            /**Establish a connection. **/
            LinkKit.getInstance().init(params, new ILinkKitConnectListener() {
                public void onError(AError aError) {
                    ALog.e(TAG, "Init Error error=" + aError);
                public void onInitDone(InitResult initResult) {
                    ALog.i(TAG, "onInitDone result=" + initResult);
                    // Obtain the topological relationships of the gateway and check whether a topological relationship exists between the gateway and the sub-device.
                    // If a topological relationship exists between the gateway and the sub-device, the gateway connects the sub-device to IoT Platform.
                    // Dynamically register the sub-device to obtain a DeviceSecret for the sub-device. If the gateway has obtained the certificate of the sub-device, skip this step.
                    // When you register the sub-device, set the deviceName parameter to the serial number or MAC address of the sub-device.
                    //Specify the information about the sub-device for which you want to add a topological relationship.

Test the connection

After you configure the information about the gateway device in the device SDK, you can test the connection between the gateway device and IoT Platform.

  1. Run DeviceTopoManager.
  2. Log on to the IoT Platform console.In the left-side navigation pane, choose Devices > Devices.
  3. On the Devices page, find the gateway device and check its status. If the status of the gateway device is Online, the gateway device is connected to IoT Platform.

What to do next

Connect the sub-device to IoT Platform