Data compression
IoT Platform supports data compression for messages transmitted between devices and the platform, helping reduce device traffic and accelerate transmission.
Prerequisites
Limits
The data compression feature is available only for Exclusive Enterprise Edition instances and Standard Enterprise Edition instances. For more information, see Purchase an Enterprise instance.
Background information
Some IoT devices rely on cellular networks with high traffic costs. Data compression reduces the size of transmitted data, lowering traffic usage and costs.
For more information about data compression and transmission, see Data compression.
Directly connected devices
Specify topics for compression and decompression
In the following sample code:
-
compTopicList: topics for server-to-device messages. The server compresses data, and devices decompress data. -
decompTopicList: topics for device-to-server messages. Devices compress data, and the server decompresses data. Thehit data compression casedebugging logs are generated on the devices.
-
Compression and decompression relationships are stored on the server. To remove them from a topic, you must disable compression and decompression in the device SDK.
If compression and decompression are still enabled on the server and a device connects to IoT Platform with an SDK that does not support data compression, communication issues may occur.
-
Do not specify the
/sys/${productKey}/${deviceName}/thing/dsltemplate/get_replytopic forcompTopicList. Otherwise, the device SDK may fail to initialize. -
Topics with wildcard characters are not supported for data compression and decompression.
// Specify the topics that are used when the server compresses data and devices decompress data.
String compTopic = "/" + deviceInfoData.productKey + "/" + deviceInfoData.deviceName + "/user/get";
List<String> compTopicList = new ArrayList<>();
compTopicList.add(compTopic);
// Specify the topics that are used when devices compress data and the server decompresses data.
String decompTopic = "/sys/" + deviceInfoData.productKey + "/" + deviceInfoData.deviceName + "/thing/event/property/post";
List<String> decompTopicList = new ArrayList<>();
decompTopicList.add(decompTopic);
ICompressor compressor = LinkKit.getInstance().getCompressor();
compressor.setCompressTopics(compTopicList, decompTopicList, new IConnectSendListener() {
@Override
public void onResponse(ARequest aRequest, AResponse aResponse) {
// Configure the custom business logic, such as property reporting.
}
@Override
public void onFailure(ARequest aRequest, AError aError) {
}
});
In the setCompressTopics method:
-
The first parameter specifies topics for server-to-device compression. The value can be
null. -
The second parameter specifies topics for device-to-server compression. The value can be
null.
Disable compression and decompression
ICompressor compressor = LinkKit.getInstance().getCompressor();
compressor.setCompressTopics(null, null, new IConnectSendListener() {
@Override
public void onResponse(ARequest aRequest, AResponse aResponse) {
//TODO: your logic
}
@Override
public void onFailure(ARequest aRequest, AError aError) {
}
});
Gateways and sub-devices
Specify topics for compression and decompression
In the following sample code:
-
compTopicList: topics for server-to-device messages. The server compresses data, and devices decompress data. -
decompTopicList: topics for device-to-server messages. Devices compress data, and the server decompresses data. Thehit data compression casedebugging logs are generated on the devices.
-
Compression and decompression relationships are stored on the server. To remove them from a topic, you must disable compression and decompression in the device SDK.
If compression and decompression are still enabled on the server and a device connects to IoT Platform with an SDK that does not support data compression, communication issues may occur.
-
Topics with wildcard characters are not supported for data compression and decompression.
-
A gateway and its sub-devices cannot use compression and decompression at the same time.
// Compress data only after the sub-device connects to IoT Platform.
final DeviceInfo info = new DeviceInfo();
// Set the info parameter to the description of a sub-device that is connected to IoT Platform.
// info = userSubDev.get(index);
// Specify the topics that are used when the server compresses data and devices decompress data.
String compTopic = "/" + info.productKey + "/" + info.deviceName + "/user/get";
List<String> compTopicList = new ArrayList<>();
compTopicList.add(compTopic);
// Specify the topics that are used when devices compress data and the server decompresses data.
String decompTopic = "/sys/" + info.productKey + "/" + info.deviceName + "/thing/event/property/post";
List<String> decompTopicList = new ArrayList<>();
decompTopicList.add(decompTopic);
String detopic2 = "/" + info.productKey + "/" + info.deviceName + "/user/update";
decompTopicList.add(detopic2);
LinkKit.getInstance().getGateway().gatewaySubDeviceSetCompressTopics(info, compTopicList, decompTopicList, new ISubDeviceActionListener() {
@Override
public void onSuccess() {
// Specify the messages that the sub-device submits to IoT Platform, such as device properties.
}
@Override
public void onFailed(AError aError) {
}
});
Disable compression and decompression
LinkKit.getInstance().getGateway().gatewaySubDeviceSetCompressTopics(info, null, null, new ISubDeviceActionListener() {
@Override
public void onSuccess() {
// Specify the messages that the sub-device submits to IoT Platform, such as device properties.
}
@Override
public void onFailed(AError aError) {
}
});