All Products
Search
Document Center

IoT Platform:Data compression

Last Updated:Sep 19, 2023

The data compression feature of IoT Platform allows you to transmit compressed data between IoT Platform and devices. You can compress the messages that you want to transmit to reduce device traffic and accelerate transmission speed. This topic describes how to use the data compression feature.

Prerequisites

Limits

The data compression feature is available only for Exclusive Enterprise Edition instances and Standard Enterprise Edition instances. For more information, see Purchase Enterprise Edition instances.

Background information

Several IoT devices use cellular networks, which causes high traffic costs. You can use the data compression feature to compress data that you want to transmit to reduce traffic and costs.

For more information about how to compress and transmit data, see Data compression.

Directly connected devices

Specify topics for compression and decompression

In the following sample code:

  • compTopicList: specifies topics that the server uses to deliver messages to devices. The server compresses data, and the devices decompress data.

  • decompTopicList: specifies topics that devices use to submit messages to the server. Devices compress data, and the server decompresses data. The hit data compression case debugging logs are generated on the devices.

Important
  • The configured compression and decompression relationships are stored on the server. You must cancel the compression and decompression operations on the device SDK to cancel the compression and decompression operations on the topic.

    If the compression and decompression operations are not disabled on the server and devices use an SDK that does not support data compression to connect to IoT Platform, communication issues may occur between the server and devices.

  • You cannot specify the /sys/${productKey}/${deviceName}/thing/dsltemplate/get_reply topic for the compTopicList parameter. Otherwise, the device SDK may fail to be initialized.

  • You cannot specify topics with wildcard characters 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) {

    }
});
Important

In the setCompressTopics method:

  • The first input parameter specifies the topics that are used when the server compresses data and devices decompress data. The value can be null.

  • The second input parameter specifies the topics that are used when devices compress data and the server compresses data. 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: specifies topics that the server uses to deliver messages to devices. The server compresses data, and the devices decompress data.

  • decompTopicList: specifies topics that devices use to submit messages to the server. Devices compress data, and the server decompresses data. The hit data compression case debugging logs are generated on the devices.

Important
  • The configured compression and decompression relationships are stored on the server. You must cancel the compression and decompression operations on the device SDK to cancel the compression and decompression operations on the topic.

    If the compression and decompression operations are not disabled on the server and devices use an SDK that does not support data compression to connect to IoT Platform, communication issues may occur between the server and devices.

  • You cannot specify topics with wildcard characters for data compression and decompression.

  • A gateway and its sub-devices cannot implement 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) {

    }
});