All Products
Search
Document Center

IoT Platform:Data compression

Last Updated:Aug 30, 2023

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

Limits

  • The data compression feature is available only for Standard and Exclusive Enterprise Edition instances.

  • The data compression feature is available only for devices that are connected to IoT Platform over Message Queuing Telemetry Transport (MQTT).

  • You can compress or decompress the data of up to 20 topics of a device. The names of the topics cannot contain wildcard characters.

  • Data is compressed into the GZIP format by using the deflate compression algorithm.

  • The data that you want to compress cannot exceed 1 MB in size.

Background information

Description

The data compression feature is implemented based on the topics that are used for communication between IoT Platform and devices. IoT Platform automatically compresses and decompresses the data of topics. User-side business systems do not need to obtain the details of the process.

Only the payloads of MQTT messages can be compressed. The payloads are compressed into the GZIP format.

You can specify the topics whose data you want to compress for a device. In most cases, the data of topics that contain large data packages needs to be compressed.

image

Process

  1. A device submits topics whose data needs to be compressed or decompressed.

  2. The device submits the compressed data or IoT Platform sends the compressed data.

image

Submit topics whose data needs to be compressed

A device submits topics only once. After the device is restarted, the topics remain unchanged.

  • Submit topics

    Connection method

    Topic

    Connection over MQTT

    /sys/${productKey}/${deviceName}/codec/topic/update

    Connection by using an MQTT gateway

    $iot/things/codec/topic/update

    The format of the payloads of messages that the device submits to the topics remains unchanged regardless of the connection method that is used. Sample payload:

    {
        "id":1,
        "version": 1.0,
        "params": [
            {
                "topic": "/productKey/deviceName/user/update",
                "operation": "compress",
                "format": "gzip"
            },
            {
                "topic": "/productKey/deviceName/user/test",
                "operation": "decompress",
                "format": "gzip"
            }
        ]
    }

    Parameter

    Description

    topic

    The name of the topic that receives the messages to be compressed. You must specify a complete topic. The name of the topic cannot contain wildcard characters.

    operation

    • compress: applies to upstream messages. IoT Platform compresses and sends the data.

    • decompress: applies to downstream messages. IoT Platform decompresses and forwards the data.

    format

    The compression format. Set the value to .gzip.

  • Response parameters

    Connection method

    Topic

    Connection over MQTT

    /sys/${productKey}/${deviceName}/codec/topic/update_reply

    Connection by using an MQTT gateway

    $iot/things/codec/topic/update_reply

    {
        "id": 1,
        "version": 1.0,
        "code": 200,
        "message": "success"
    }

    Parameter

    Description

    code

    • 200: The call was successful.

    • Other values: The call failed.

    message

    The description of the returned code.

Transmit compressed data

  • Upstream messages: a device uses the gzip tool to compress the payload of a message and submits the messages. Then, IoT Platform decompresses the message.

  • Downstream messages: IoT Platform sends a message that is compressed by using the gzip tool to a device. The device decompresses the payload of the message and forwards the message to a business system.

For more information, see Examples.