Skip to content

MQTT Protocol

MQTT Connection Parameters

  1. Keep Alive: 60s
  2. Clean Start: 0

Limitations

  1. If the size of each message sent by the device exceeds 1M, it may cause data parsing errors. It is recommended to use packet splitting.

MQTT Connection Authentication

clientId: ${ProductKey}+"&"+${DeviceKey}
username: ${ProductKey}+"&"+${DeviceKey};${timestamp:milliseconds}
password: hmacsha256(secret:${deviceSecret},digest body: ${timestamp})

Topic

Topic Description

Upstream Topic refers to the device sending messages to the platform. Downstream Topic refers to the application sending messages to the device.

Data Compression

The protocol supports data compression for long messages. By compressing data before transmission, you can save device bandwidth and improve transmission speed.

Data Compression Topic Description

Add /gzip suffix to the regular Topic, compress the request body using Gzip, and then send it. The cloud platform will decompress and process it.
Example:
Device Property Reporting: $thing/up/property/{productKey}/{DeviceKey}/gzip
Request Data Format (gzip compress the following JSON before sending):

json
{
  "msgId": "123",
  "method": "report",
  "ts": 1628646783000,
  "params": {
    "power_switch": 1,
    "brightness": 32
  }
}

Gateway Proxy Online/Offline

Functional Overview

Gateway type devices can proxy the online and offline operations of their sub-devices through data communication with the cloud.

  • Data Upstream Topic (for publishing): $gateway/operation/up/${ProductKey}/${DeviceKey}
  • Data Downstream Topic (for subscription): $gateway/operation/down/${ProductKey}/${DeviceKey}

Proxy Sub-device Online

Gateway type devices can proxy sub-devices to go online via the data upstream topic. After a successful request, the cloud returns the sub-device online result information via the data downstream topic. Gateway Proxy Sub-device Online Request Data Format:

json
{
  "type": "online",
  "msgId": "123",
  "ts": 1628646783000,
  "payload": {
    "devices": [
      {
        "productKey": "CFC******AG7",
        "deviceKey": "subdeviceaaaa"
      }
    ]
  }
}

Gateway Proxy Sub-device Online Response Data Format:

json
{
  "type": "online",
  "msgId": "123",
  "payload": {
    "devices": [
      {
        "productKey": "CFC******AG7",
        "deviceKey": "subdeviceaaaa",
        "result": 0 
      }
    ]
  }
}

Request Parameter Field Description:

FieldTypeDescription
typeStringDevice online/offline status, online: online, offline: offline
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongOnline time, millisecond timestamp
payloadObjectParameter information
payload.devicesArrayDevice information list
payload.devices.productKeyStringSub-device Product Key
payload.devices.deviceKeyStringSub-device Key

Response Parameter Field Description:

FieldTypeDescription
typeStringCorresponding request type
msgIdStringCorresponding request msgId, used for correlation
payloadObjectParameter information
payload.devicesArrayDevice information list
payload.devices.productKeyStringSub-device Product Key
payload.devices.deviceKeyStringSub-device Key
payload.devices.resultIntegerSub-device online result, 0 means success, see table below for specific error codes

Proxy Sub-device Offline

Gateway type devices can proxy sub-devices to go offline via the data upstream topic. After a successful request, the cloud returns the successful sub-device offline information via the data downstream topic.
Gateway Proxy Sub-device Offline Request Data Format:

json
{
  "type": "offline",
  "msgId": "123",
  "ts": 1628646783000,
  "payload": {
    "devices": [
      {
        "productKey": "CFC******AG7",
        "deviceKey": "subdeviceaaaa"
      }
    ]
  }
}

Gateway Proxy Sub-device Offline Response Data Format:

json
{
  "type": "offline",
  "msgId": "123",
  "payload": {
    "devices": [
      {
        "productKey": "CFC******AG7",
        "deviceKey": "subdeviceaaaa",
        "result": 0 
      }
    ]
  }
}

Request Parameter Description:

FieldTypeDescription
typeStringDevice online/offline status, online: online, offline: offline
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongOnline time, millisecond timestamp
payloadObjectParameter information
payload.devicesArrayDevice information list
payload.devices.productKeyStringSub-device Product Key
payload.devices.deviceKeyStringSub-device Key

Response Parameter Description:

FieldTypeDescription
typeStringCorresponding request type
msgIdStringCorresponding request msgId, used for correlation
payloadObjectParameter information
payload.devicesArrayDevice information list
payload.devices.productKeyStringSub-device Product Key
payload.devices.deviceKeyStringSub-device Key
payload.devices.resultIntegerSub-device online result, 0 means success, see table below for specific error codes

Error Codes

Error CodeDescription
0Success
1The gateway device is not bound to this sub-device
2System error, sub-device online or offline failed

Proxy Sub-device Publish and Subscribe

Functional Overview

Gateway type devices can proxy the publishing and subscription of messages for their sub-devices through data communication with the cloud.

Publish and Subscribe Messages

After the gateway product establishes a binding with the sub-product and obtains the Topic permissions of the sub-device, the gateway device can use the sub-device Topic proxy to send and receive messages.

Device Property Reporting

Data Upstream Topic (for publishing): $thing/up/property/{productKey}/{DeviceKey}
Data Downstream Topic (for subscription): $thing/down/property/{productKey}/{DeviceKey}
Request Data Format:

json
{
  "msgId": "123",
  "method": "report",
  "ts": 1628646783000,
  "params": {
    "power_switch": 1,
    "brightness": 32
  }
}

Response Data Format:

json
{
    "method":"report_reply",
    "msgId":"123",
    "code":0,
    "status": ""
}

Request Parameter Description:

FieldTypeDescription
methodStringreport indicates property reporting, fixed value.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongTime reported by the device. Millisecond timestamp
paramsObjectProperty values reported by the device
params.power_switchBooleanBoolean value is generally true/false
payload.brightnessIntegerInteger type property is an integer value

Response Parameter Description:

FieldTypeDescription
methodStringreport_reply indicates the response message for property reporting
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Device Property Reporting Data Compression

When reporting many properties, you can compress data to save device bandwidth and improve transmission speed.
For details, please refer to the Data Compression section.
Data Upstream Topic (for publishing): $thing/up/property/{productKey}/{DeviceKey}/gzip

The request data format is the same as the normal format, as shown below. You need to gzip compress the entire JSON before sending:

json
{
  "msgId": "123",
  "method": "report",
  "ts": 1628646783000,
  "params": {
    "power_switch": 1,
    "brightness": 32
  }
}

Property Setting

When controlling the device via the cloud, the device needs to subscribe to the downstream Topic to receive cloud commands:
Downstream Topic: $thing/down/property/{ProductKey}/{DeviceKey}
Upstream Topic: $thing/up/property/{ProductKey}/{DeviceKey}
Downstream Data Format:

json
{
  "msgId": "123",
  "method": "control",
  "ts": 1628646783000,
  "params": {
    "power_switch": 1,
    "color": 1,
    "brightness": 32
  }
}

Upstream Data Format:

json
{
  "msgId": "123",
  "method": "control_reply",
  "code": 0,
  "status": ""
}

Request Parameter Description:

FieldTypeDescription
methodStringcontrol indicates property setting, fixed value.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongCommand issuance time. Millisecond timestamp
paramsObjectDevice property setting values

Response Parameter Description:

FieldTypeDescription
methodStringcontrol_reply indicates the response message for property setting
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Gateway Batch Reporting

Gateway type devices quickly report property change information for sub-devices and themselves in batches.
Upstream Topic: $thing/up/property/gateway/{ProductKey}/{DeviceKey}
Downstream Topic: $thing/down/property/gateway/{ProductKey}/{DeviceKey}
Request Data Format:

json
{
  "msgId": "123",
  "method": "report",
  "ts": 1212121221,
  "params": {
    "properties": {
      "values": {
        "power_switch": 1,
        "color": 1,
        "brightness": 32
      },
      "ts": 1212121221
    },
    "subDevices": [
      {
        "productKey": "",
        "deviceKey": "",
        "properties": {
          "values": {
            "power_switch": 1,
            "color": 1,
            "brightness": 32
          },
          "ts": 1212121221
        }
      }
    ]
  }
}

Response Data Format:

json
{
  "msgId": "123",
  "method": "report_reply",
  "code": 0,
  "status": ""
}

Request Parameter Description:

FieldTypeDescription
methodStringreport indicates property reporting, fixed value.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongRequest time. Millisecond timestamp
paramsObjectDevice property setting values
params.propertiesObjectProperty changes of the gateway device itself
params.properties.tsLongProperty change time point. Millisecond timestamp
params.properties.valuesMapProperty values reported by the gateway device
params.subDevicesArrayList of gateway sub-device property values
params.subDevices.productKeyStringSub-device Product Key
params.subDevices.deviceKeyStringSub-device Key
params.subDevices.propertiesObjectSub-device property value information
params.subDevices.properties.tsLongSub-device property change time
params.subDevices.properties.valuesMapSub-device property values, KV pairs

Response Parameter Description:

FieldTypeDescription
methodStringreport_reply indicates the response message for property setting
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Service Invocation

Application invokes device action (Downstream) Topic: $thing/down/service/{ProductKey}/{DeviceKey}
Device responds to action execution result (Upstream) Topic: $thing/up/service/{ProductKey}/{DeviceKey}
Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "openDoor",
  "ts": 1212121221,
  "params": {
    "userid": "323343"
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",
  "code": 0,
  "status": "some message where error",
  "response": {
    "Code": 0
  }
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongRequest time. Millisecond timestamp
serviceIdStringService identifier in the Thing Model. Defined in the Thing Model.
paramsObjectRequest parameters defined in the service of the Thing Model

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
responseObjectResponse parameters defined in the service of the Thing Model

Peak Shaving and Valley Filling Data

Issue Control

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "peakShaving",
  "ts": 1212121221,
  "params": {
    "strategyName": "Strategy Name",
    "startDate": "2024-07-01",
    "endDate": "2024-07-30",
    "maxChargingPower": 0,
    "maxDischargePower": 0,
    "socUpperLimit": 95,
    "socLowerLimit": 5,
    "status": 1,
    "strategyParam": [
      {
        "startTime": "00:00",
        "endTime": "01:00",
        "pattern": 0,
        "activePower": 100
      }
    ]
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error"
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringPeak shaving fixed as peakShaving
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.strategyNameStringStrategy Name
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time
params.maxChargingPowerIntMax charging power: default 0 Unit: W
params.maxDischargePowerIntMax discharging power: default 0 Unit: W
params.socUpperLimitIntSOC Upper Limit: default 0
params.socLowerLimitIntSOC Lower Limit: default 0
params.statusIntStrategy enable status: default enabled if not passed 1-Enable 0-Disable
params.strategyParamArrayStrategy configuration parameters
params.strategyParam.startTimeStringStart time: 15-minute interval, must be less than end time
Time format 00:15, 00:30
params.strategyParam.endTimeStringEnd time: 15-minute interval, must be greater than start time
Time format 00:15, 00:30
params.strategyParam.patternIntPattern 1-Charge 2-Standby 3-Discharge
params.strategyParam.activePowerIntActive Power Unit: W

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
Get Strategy

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "getPeakShaving",
  "ts": 1212121221,
  "params": {
    "startDate": "2024-07-01",
    "endDate": "2024-07-30"
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error",
  "response": {
    "strategy":[
      {
        "strategyName": "Strategy Name",
        "startDate": "2024-07-01",
        "endDate": "2024-07-30",
        "maxChargingPower": 0,
        "maxDischargePower": 0,
        "socUpperLimit": 95,
        "socLowerLimit": 5,
        "strategyParam": [
          {
            "startTime": "00:00",
            "endTime": "01:00",
            "pattern": 0,
            "activePower": 100
          }
        ]
      }
    ]
  }
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringPeak shaving fixed as getPeakShaving
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
responseObjectResponse parameters
response.strategyArrayStrategy List
response.strategy.strategyNameStringStrategy Name
response.strategy.startDateStringStart time, must be less than end time
response.strategy.endDateStringEnd time, must be greater than start time
response.strategy.maxChargingPowerIntMax charging power Unit: W
response.strategy.maxDischargePowerIntMax discharging power Unit: W
response.strategy.socUpperLimitIntSOC Upper Limit
response.strategy.socLowerLimitIntSOC Lower Limit
response.strategy.strategyParamArrayStrategy configuration parameters
response.strategy.strategyParam.startTimeStringStart time: 15-minute interval, must be less than end time
Time format 00:15, 00:30
response.strategy.strategyParam.endTimeStringEnd time: 15-minute interval, must be greater than start time
Time format 00:15, 00:30
response.strategy.strategyParam.patternIntPattern 1-Charge 2-Standby 3-Discharge
response.strategy.strategyParam.activePowerIntActive Power Unit: W

Anti-Reflux

Issue Control

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "antiReflux",
  "ts": 1212121221,
  "params": {
    "strategyName": "Strategy Name",
    "startDate": "2024-07-01",
    "endDate": "2024-07-30",
    "refluxThresholdValue": 1,
    "refluxMaxValue": 1,
    "refluxMinValue": 1,
    "refluxStatus": 1,
    "executionInterval": 60
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error"
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringAnti-reflux fixed as antiReflux
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time
params.strategyNameStringStrategy Name
params.refluxThresholdValueStringAnti-reflux threshold
params.refluxMaxValueStringAnti-reflux dead zone upper limit
params.refluxMinValueIntAnti-reflux dead zone lower limit
params.refluxStatusIntAnti-reflux enable status: default enabled if not passed 1-Enable 0-Disable
params.executionIntervalIntExecution interval: Unit seconds, default 60 seconds if not passed

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
Get Strategy

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "getAntiReflux",
  "ts": 1212121221,
  "params": {
    "startDate": "2024-07-01",
    "endDate": "2024-07-30"
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error",
  "response": {
    "strategy": [
      {
        "strategyName": "Strategy Name",
        "startDate": "2024-07-01",
        "endDate": "2024-07-30",
        "refluxThresholdValue": 1,
        "refluxMaxValue": 1,
        "refluxMinValue": 1,
        "executionInterval": 60
      }
    ]
  }
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringAnti-reflux fixed as getAntiReflux
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
responseObjectResponse parameters
response.strategyArrayStrategy List
response.strategy.strategyNameStringStrategy Name
response.strategy.startDateStringStart time, must be less than end time
response.strategy.endDateStringEnd time, must be greater than start time
response.strategy.refluxThresholdValueIntAnti-reflux threshold
response.strategy.refluxMaxValueIntAnti-reflux dead zone upper limit Unit: W
response.strategy.refluxMinValueIntAnti-reflux dead zone lower limit Unit: W
response.strategy.executionIntervalIntExecution interval: Unit seconds

Demand Control

Issue Control

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "demandControl",
  "ts": 1212121221,
  "params": {
    "strategyName": "Strategy Name",    
    "startDate": "2024-07-01",
    "endDate": "2024-07-30",
    "overDemandThresholdValue": 1,
    "overDemandMaxValue": 1,
    "overDemandMinValue": 1,
    "overDemandStatus": 1,
    "executionInterval": 60
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error"
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringDemand control fixed as demandControl
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.strategyNameStringStrategy Name
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time
params.overDemandThresholdValueIntAnti-excess demand threshold Unit: W
params.overDemandMaxValueIntAnti-excess demand dead zone upper limit Unit: W
params.overDemandMinValueIntAnti-excess demand dead zone lower limit Unit: W
params.overDemandStatusIntAnti-excess demand enable status: default enabled if not passed 1-Enable 0-Disable
params.executionIntervalIntExecution interval: Unit seconds, default 60 seconds if not passed

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
Get Strategy

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "getDemandControl",
  "ts": 1212121221,
  "params": { 
    "startDate": "2024-07-01",
    "endDate": "2024-07-30"
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error",
  "response": {
    "strategy": [
      {
        "strategyName": "Strategy Name",    
        "startDate": "2024-07-01",
        "endDate": "2024-07-30",
        "overDemandThresholdValue": 1,
        "overDemandMaxValue": 1,
        "overDemandMinValue": 1,
        "executionInterval": 60
      }
    ]
  }
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringDemand control fixed as getDemandControl
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
responseObjectResponse parameters
response.strategyArrayStrategy List
response.strategy.strategyNameStringStrategy Name
response.strategy.startDateStringStart time, must be less than end time
response.strategy.endDateStringEnd time, must be greater than start time
response.strategy.overDemandThresholdValueIntAnti-excess demand threshold Unit: W
response.strategy.overDemandMaxValueIntAnti-excess demand dead zone upper limit Unit: W
response.strategy.overDemandMinValueIntAnti-excess demand dead zone lower limit Unit: W
response.strategy.executionIntervalIntExecution interval: Unit seconds

Dynamic Expansion

Issue Control

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "dynamicExpansion",
  "ts": 1212121221,
  "params": {
    "strategyName": "Strategy Name",    
    "startDate": "2024-07-01",
    "endDate": "2024-07-30",
    "expansionThresholdValue": 7500,
    "expansionMaxValue": 7900,
    "expansionMinValue": 7200,
    "expansionStatus": 1
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error"
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringDynamic expansion fixed as getDynamicExpansion
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.strategyNameStringStrategy Name
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time
params.expansionThresholdValueIntTarget Value Unit: VA
params.expansionMaxValueIntDynamic expansion dead zone upper limit Unit: VA
params.expansionMinValueIntDynamic expansion dead zone lower limit Unit: VA
params.expansionStatusIntDynamic expansion enable status: default enabled if not passed 1-Enable 0-Disable

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
Get Strategy

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "getDynamicExpansion",
  "ts": 1212121221,
  "params": { 
    "startDate": "2024-07-01",
    "endDate": "2024-07-30"
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error",
  "response": {
    "strategy": [
      {
        "strategyName": "Strategy Name",    
        "startDate": "2024-07-01",
        "endDate": "2024-07-30",
        "expansionThresholdValue": 7500,
        "expansionMaxValue": 7900,
        "expansionMinValue": 7200,
        "expansionStatus": 1
      }
    ]
  }
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringDynamic expansion fixed as getDynamicExpansion
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.startDateStringStart time, must be less than end time
params.endDateStringEnd time, must be greater than start time

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure
responseObjectResponse parameters
response.strategyArrayStrategy List
response.strategy.strategyNameStringStrategy Name
response.strategy.startDateStringStart time, must be less than end time
response.strategy.endDateStringEnd time, must be greater than start time
params.expansionThresholdValueIntTarget Value Unit: VA
params.expansionMaxValueIntDynamic expansion dead zone upper limit Unit: VA
params.expansionMinValueIntDynamic expansion dead zone lower limit Unit: VA
params.expansionStatusIntDynamic expansion enable status: default enabled if not passed 1-Enable 0-Disable

Electricity Price Issuance

Issue Electricity Price

Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "electricityConfig",
  "ts": 1212121221,
  "params": {
    "periodType": [
      {
        "type": "sharp",
        "name": "Sharp"
      },
      {
        "type": "peak",
        "name": "Peak"
      },
      {
        "type": "shoulders",
        "name": "Shoulder"
      },
      {
        "type": "off_peak",
        "name": "Off-peak"
      },
      {
        "type": "deep_valley",
        "name": "Deep Valley"
      }
    ],
    "electricityConfig": [
      {
        "date": "2024-07-01",
        "schemeId": 1
      }
    ],
    "schemes": [
      {
        "schemeId": 1,
        "schemeName": "Scheme Name",
        "year": 2024,
        "type": "TWO_PART",
        "type2": "normal",
        "method": "TRANSFORMER",
        "demand": 1000000,
        "demandPrice": "0.3",  
        "capacity": 1000000,
        "capacityPrice": "0.3",
        "periodPrice": [
          {
            "type": "peak",
            "buyPrice": 3000,
            "salePrice": 3000
          },
          {
            "type": "off_peak",
            "buyPrice": 3000,
            "salePrice": 3000
          }
        ],
        "periodTime": [
          {
            "type": "peak",
            "startTime": "00:00",
            "endTime": "01:00"
          },
          {
            "type": "off_peak",
            "startTime": "01:00",
            "endTime": "02:00"
          },
          {
            "type": "peak",
            "startTime": "02:00",
            "endTime": "03:00"
          },
          {
            "type": "off_peak",
            "startTime": "03:00",
            "endTime": "04:00"
          }
        ]
      }
    ]
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",  
  "code": 0,
  "status": "some message where error"
}

Request Parameter Description:

FieldTypeDescription
methodStringaction indicates invoking a service of the device, fixed value.
msgIdStringCorresponding request msgId, used for correlation
serviceIdStringElectricity price issuance fixed as electricityConfig
tsLongMillisecond timestamp
paramsObjectRequest parameters
params.periodTypeArrayElectricity price period type
params.periodType.typeStringPeriod type
params.periodType.nameStringPeriod name
params.electricityConfigArrayElectricity price configuration
params.electricityConfig.dateStringDate
params.electricityConfig.schemeIdLongScheme ID
params.schemesArrayElectricity price scheme
params.schemes.schemeIdLongScheme ID
params.schemes.schemeNameStringScheme name
params.schemes.yearIntYear
params.schemes.typeStringElectricity price type UNITARY: Unitary system, TWO_PART: Two-part system
params.schemes.type2StringElectricity price type normal: General industrial and commercial, largeIndustry: Large industrial
params.schemes.methodStringBilling method TRANSFORMER: Transformer capacity, MAX_DEMAND: Maximum demand
params.schemes.demandLongMaximum demand Unit: W
params.schemes.demandPriceStringMaximum demand price Unit: milli/kW month
params.schemes.capacityLongTransformer capacity Unit: V
params.schemes.capacityPriceStringTransformer capacity price Unit: milli/kVA month
params.schemes.periodTimeArrayElectricity price period
params.schemes.periodTime.typeStringPeriod type, refer to periodType
params.schemes.periodTime.startTimeStringStart time
params.schemes.periodTime.endTimeStringEnd time
params.schemes.periodPriceArrayElectricity price period
params.schemes.periodPrice.typeStringPeriod type, refer to periodType
params.schemes.periodPrice.buyPriceLongBuying price (milli/kWh) e.g.: 1 Yuan/kWh is 10000
params.schemes.periodPrice.salePriceLongSelling price (milli/kWh) e.g.: 1 Yuan/kWh is 10000

Response Parameter Description:

FieldTypeDescription
methodStringaction_reply indicates the response message for service invocation
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Event Reporting

Device Event Upstream Request Topic: $thing/up/event/{ProductKey}/{DeviceKey}
Device Event Downstream Response Topic: $thing/down/event/{ProductKey}/{DeviceKey}
Upstream Data Format:

json
{
  "method": "event_post",
  "msgId": "123",
  "eventId": "PowerAlarm",
  "type": "error",
  "ts": 1212121221,
  "params": {
    "Voltage": 2.8,
    "Percent": 20
  }
}

Response Data Format:

json
{
    "method": "event_reply",
    "msgId": "123",
    "code": 0,
    "status": ""
}

Request Parameter Description:

FieldTypeDescription
methodStringevent_post indicates invoking event reporting, fixed value.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongRequest time. Millisecond timestamp
eventIdStringEvent identifier in the Thing Model. Defined in the Thing Model.
paramsObjectResponse parameters defined in the event of the Thing Model
typeStringEvent type, values: INFO/WARNING/ERROR

Response Parameter Description:

FieldTypeDescription
methodStringevent_reply indicates the response message for event reporting
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Time Synchronization

Data Upstream Topic (for publishing): time-sync/up/{ProductKey}/{DeviceKey}
Data Downstream Topic (for subscription): time-sync/down/{ProductKey}/{DeviceKey}
Upstream Data Format:

json
{
  "deviceSendTime":"1571724098000"
}

Downstream Data Format:

json
{
  "deviceSendTime": "1571724098000",
  "serverRecvTime": "1571724098110",
  "serverSendTime": "1571724098115"
}

Assuming the request latency and response latency are the same, and the time the device receives the server message is ${deviceRecvTime}, then the precise time on the device is: (${serverRecvTime}+${serverSendTime}+${deviceRecvTime}-${deviceSendTime})/2.

Request Parameter Description:

FieldTypeDescription
deviceSendTimeLongClient request time, millisecond timestamp

Response Parameter Description:

FieldTypeDescription
deviceSendTimeLongClient request time, millisecond timestamp
serverRecvTimeLongServer received message time, millisecond timestamp
serverSendTimeLongServer reply message time, millisecond timestamp

Log Collection

Log Collection Service Invocation

Data Downstream Topic (for subscription): $thing/down/service/{ProductKey}/{DeviceKey}
Data Upstream Topic (for publishing): $thing/up/service/{ProductKey}/{DeviceKey}
Downstream Data Format:

json
{
  "method": "action",
  "msgId": "1234",
  "serviceId": "$log",
  "ts": 1212121221,
  "params": {
    "switch": "on",
    "endTime": 1571724098110
  }
}

Upstream Data Format:

json
{
  "method": "action_reply",
  "msgId": "1234",
  "code": 0,
  "status": "some message where error"
}

Request Parameter Field Description:

FieldTypeDescription
methodStringService invocation fixed value: "action". Indicates invoking a behavior of the device.
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
serviceIdStringSystem parameter. Fixed as $log
tsLongTime of behavior invocation, in milliseconds
switchStringOptional parameter. Device-side log collection switch.
on: Enable device-side log collection function.
off: Disable device-side log collection switch.
endTimeLongOptional, log collection end time

Response Parameter Field Description:

FieldTypeDescription
methodStringInvocation response fixed value: "action_reply". Indicates the response replied to the cloud after the device completes execution.
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

Log Reporting

Data Downstream Topic (for subscription): $thing/up/log/{ProductKey}/{DeviceKey}
Data Upstream Topic (for publishing): $thing/down/log/{ProductKey}/{DeviceKey}
Downstream Data Format:

json
{
  "msgId": "1234",
  "serviceId": "$log",  // Fixed as $log	
  "ts": 1212121221,
  "params": [{
    "time": "on",
    "level": "INFO",
    "type": "Type",
    "content": "Log Content"
  }]
}

Upstream Data Format:

json
{
  "msgId": "1234",
  "code": 0,
  "status": "some message where error"  // Error message
}

Request Parameter Field Description:

FieldTypeDescription
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
tsLongTime of behavior invocation, in milliseconds.
paramsArrayLog details
timeLongLog generation time
levelStringLog level, values: INFO/WARNING/ERROR
typeStringLog type, self-defined
contentStringLog body content

Response Parameter Field Description:

FieldTypeDescription
msgIdStringCorresponding request msgId, used for correlation
codeIntegerExecution result, 0 means success
statusStringError description after execution failure

OTA

OTA Process

  1. Report device version information when device connection initializes ($ota/device/inform/{ProductKey}/{DeviceKey})
  2. Backend uploads firmware upgrade package and initiates OTA push to the device
  3. Firmware push update $ota/update/{ProductKey}/{DeviceKey}
  4. Report upgrade progress ($ota/report/progress/{ProductKey}/{DeviceKey})
  5. Report latest version after device upgrade is complete ($ota/device/inform/{ProductKey}/{DeviceKey})

Firmware Push Logic

Every time device version information is reported, it checks if the current device matches the latest firmware version. If inconsistent, a firmware update is pushed.

Version Reporting

Data Upstream Topic (for publishing): $ota/device/inform/{ProductKey}/{DeviceKey}

json
{
  "msgId": 1,
  "params": {
    "version": "1.0.0",
    "module":"mcu"
  }
}

Request Parameter Field Description:

FieldTypeDescription
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
versionStringVersion number
moduleStringModule name, can be omitted when reporting the device itself (default)

Report Upgrade Progress

Data Upstream Topic (for publishing): $ota/report/progress/{ProductKey}/{DeviceKey}

json
{
    "msgId": "123",
    "params": {
        "step": "-1",
        "desc": "OTA upgrade failed, cannot request upgrade package information.",
        "module": "MCU"
    }
}

Request Parameter Field Description:

FieldTypeDescription
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
stepStringUpgrade progress, progress value and description reported by the device,
Integer 1~100: Upgrade progress percentage.
-1: Upgrade failed.
-2: Download failed.
-3: Verification failed.
-4: Burning failed.
descStringProgress description information, max 128 characters. Can be used to describe exception information when an exception occurs.
moduleStringModule name, can be omitted when reporting the device itself (default)

Firmware Update Push

Data Downstream Topic (for subscription): $ota/update/{ProductKey}/{DeviceKey}

json
{
  "msgId": "123",
	"size": 93796291,
	"version": "1.0.0",
	"url": "https://the_firmware_url",
	"md5": "f8d85b250d4d787a9f48***",
	"module": "MCU"
}

Return Parameter Field Description:

FieldTypeDescription
msgIdStringMessage unique identifier, ensure uniqueness for at least 24 hours. Auto-increment id can be used
sizeLongFirmware size, in bytes
versionStringVersion number
urlStringFirmware download url
md5StringMD5 value of the firmware
moduleStringModule name, no such parameter for the device itself (default)