Java Link SDK FAQ
This topic answers frequently asked questions about the Java Link SDK.
Connect to Apsara Stack using the Java Link SDK
Apsara Stack has its own TLS root certificate, which is different from the root certificate of the public cloud. To connect a device to Apsara Stack using the Java Link SDK, you must replace the root certificate. You need to find the root certificate for your Apsara Stack, such as the user_ca.crt file, to complete the replacement.
Example code:
IoTMqttClientConfig config = new IoTMqttClientConfig();
config.productKey = deviceInfo.productKey;
config.deviceName = deviceInfo.deviceName;
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("user_ca.crt");// Replace with the root certificate file of Apsara Stack.
config.channelRootCrtFile = is;// Set for the MQTT instance.
params.mqttClientConfig = config;Reconnection mechanism for gateways and sub-devices
The default timeout period for the Java Link SDK is 65 seconds. Call MqttConfigure.setKeepAliveInterval to set the timeout period. Call MqttConfigure.getKeepAliveInterval to retrieve the timeout period.
If the gateway disconnects from IoT Platform due to a network issue, the reconnection mechanism brings the gateway and its sub-devices back online after the network connection is restored.
Call the initializer function, LinkKit.getInstance().getGateway().initSubDeviceThing, for a sub-device only after its initial reconnection. Do not call this function again for subsequent reconnections.