Help Center/ IoT/ Developer Guide/ Product Development/ Developing a Codec/ Reference/ Input/Output Format of the Codec Plug-In
Updated on 2022-02-24 GMT+08:00

Input/Output Format of the Codec Plug-In

Table 1 Definition of services supported by a type of water meter

Service Type

Attribute Name

Attribute Description

Attribute Type (Data Type)

Battery

-

-

-

-

batteryLevel

Specifies the battery level in the unit of percent. The value ranges from 0 to 100.

int

Meter

-

-

-

-

signalStrength

Specifies the signal strength.

int

-

currentReading

Specifies the current read value.

int

-

dailyActivityTime

Specifies the daily activated communication duration.

string

The following shows the decode interface output for data reported by a device to the IoT platform.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
    "identifier": "12345678",
    "msgType": "deviceReq",
    "data": [
        {
            "serviceId": "Meter",
            "serviceData": {
                "currentReading": "46.3",
                "signalStrength": 16,
                "dailyActivityTime": 5706
            },
            "eventTime": "20160503T121540Z"
        },
        {
            "serviceId": "Battery",
            "serviceData": {
                "batteryLevel": 10
            },
            "eventTime": "20160503T121540Z"
        }
    ]
}

The following shows the encode interface input when the IoT platform receives data reported by the device and sends a response to the device.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
    "identifier": "123",
    "msgType": "cloudRsp",
    'request': [
        1,
        2
    ],
    "errcode": 0,
    "hasMore": 0
}
NOTE:

The value of request can be [1,2], which is simulated data. The actual value prevails.

Table 2 Order definition

Basic Function

Type

Name

Command Parameter

Data Type

Enumerated Value

WaterMeter

Water meter

-

-

-

-

-

CMD

SET_TEMPERATURE_READ_PERIOD

-

-

-

-

-

-

value

int

-

-

RSP

SET_TEMPERATURE_READ_PERIOD_RSP

-

-

-

-

-

-

result

int

  • 0: success
  • 1: invalid input
  • 2: execution failed

The following shows the input parameters of the encode interface when the IoT platform sends an order to the device.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
    "identifier": "12345678",
    "msgType": "cloudReq",
    "serviceId": "WaterMeter",
    "cmd": "SET_TEMPERATURE_READ_PERIOD",
    "paras": {
        "value": 4
    },
    "hasMore": 0
}

After the IoT platform receives a response from the device, the IoT platform invokes the decode interface for decoding. The decode interface output is as follows:

1
2
3
4
5
6
7
8
{
    "identifier": "123",
    "msgType": "deviceRsp",
    "errcode": 0,
    "body": {
        "result": 0
    }
}