Search Command


按照筛选条件查询云端向设备发送的指令信息。

请求格式

POST https://{apigw-address}/connect-service/v2.1/commands?action=search

请求参数(URI)

注解

以下非必须字段中,必须提供 assetIdproductKey + deviceKey 的组合,用于指定设备。

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织 ID。如何获取 orgId 信息>>
assetId Query 可选(见上述注解) String 资产 ID。如何获取 assetId 信息>>
productKey Query 可选(见上述注解) String 设备的 product key,需与 deviceKey 一起使用。
deviceKey Query 可选(见上述注解) String 设备的 device key,需与 productKey 一起使用。

请求参数(Body)

名称 必需/可选 数据类型 描述
expression 可选 String

查询表达式,支持类 SQL 的查询。目前支持查询的字段是 statecommandNamecreateTime

  • state 支持等于(=)运算符。
  • commandName.default 支持模糊匹配,必须提供 locale ,如 commandName.zh_CN 或 commandName.en_US、commandName.defaultValue。
  • createTime 支持用 < 和 >= 运算符来指定时间范围。指定的时间需要采用 YYYY-MM-DD HH:mm:ss 的格式,如:2019-04-17 10:30:00

如何使用查询表达式>>

pagination 可选 Pagination 请求结构体 分页参数。如未指定,默认每页 100 条。为获得最佳性能,建议每页不超过 50 条。不支持使用 sorters 参数对结果进行排序,查询结果按照 createTime,最近创建的靠前排列。Pagination 请求结构体>>
projection 可选 Projection 结构体 指定对返回结果的裁剪。参见 Projection 参数如何对结果集做裁剪

响应参数

名称 数据类型 描述
data Command 结构体数组 有关 Command 结构体的定义,参见 Command 结构体

Command 结构体

名称 数据类型 描述
commandId String 命令ID
orgId String 资产所属的组织ID。
productKey String Product Key.
deviceKey String Device Key.
assetId String 资产ID。
createTime String 创建时间。
createLocaltime String 本地创建时间。
commandType Integer 命令类型。1. 测点设置 2. 服务调用。
commandName StringI18n 命令的名称。对于测点设置来说,是测点名称。对于服务调用来说,是服务名称。
timeout Integer 命令超时时长,单位是秒,范围[1-60],默认30。
pendingTtl Long 命令缓存时长,单位是秒,范围[ 0 - 48 * 60 * 60 ],默认0,表示即时命令。
state Integer 命令状态,用1-7的整数表示。 1表示已创建;2表示已取消;3表示已过期;4表示已下发;5表示发送成功;6表示发送失败;7表示响应超时。
tslIdentifier String 物模型中的对应标识符。对于测点设置命令来说,是测点标识符。对于服务调用命令来说,是服务标识符。
inputData Map(Key为String,Value为String,Number,Array或Object) 输入数据。对于测点设置命令来说,key为测点标识符,value为需要设置的测点值。对于服务调用命令来说,为服务输入参数。value数据类型需要符合物模型的定义。
outputData Map(Key为String,Value为String,Number,Array或Object) 输出数据。对于测点设置命令来说,该字段无返回。对于服务调用命令来说,该字段表示服务的输出结果。value数据类型需要符合物模型的定义。

示例 1

请求示例

url: https://{apigw-address}/connect-service/v2.1/commands?action=search&deviceKey=yourDeviceKey&productKey=yourProductKey&orgId=yourOrgId
method: POST
requestBody:
{
        "expression":"state = 2",
        "pagination":{
                "pageNo":1,
                "pageSize":5
        }
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "requestId": "df57e058-0d8b-4700-9e38-ef30132c155f",
  "data": [
    {
      "commandId": "2322417636630765568",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688731159",
      "createLocaltime": "2019-08-13 09:32:11",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 100,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417598073053184",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688726563",
      "createLocaltime": "2019-08-13 09:32:06",
      "commandType": 2,
      "commandName": {
        "defaultValue": "service522",
        "i18nValue": {
          "en_US": "service522"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "service522",
      "inputData": {
        "service_input": 555
      },
      "outputData": null
    },
    {
      "commandId": "2322417559066025984",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688721913,
      "createLocaltime": "2019-08-13 09:32:01",
      "commandType": 2,
      "commandName": {
        "defaultValue": "service522",
        "i18nValue": {
          "en_US": "service522"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "service522",
      "inputData": {
        "service_input": 555
      },
      "outputData": null
    },
    {
      "commandId": "2322417537678745600",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688719363,
      "createLocaltime": "2019-08-13 09:31:59",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417518334615552",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": 1565688717057,
      "createLocaltime": "2019-08-13 09:31:57",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    }
  ],
  "pagination": {
    "sortedBy": [
      {
        "field": "createDate",
        "order": "DESC"
      }
    ],
    "pageNo": 1,
    "pageSize": 5,
    "totalSize": 547
  }
}

示例 2

请求示例

url: https://{apigw-address}/connect-service/v2.1/commands?action=search&deviceKey=yourDeviceKey&productKey=yourProductKey&orgId=yourOrgId
method: POST
requestBody:
{
  "expression": "commandName.zh_CN like \"Int_value\" AND createTime >= \"2019-08-13 09:00:00\"",
  "pagination": {
    "pageNo": 1,
    "pageSize": 5
  }
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "requestId": "051ab2c9-5de4-4c05-9731-042475234267",
  "data": [
    {
      "commandId": "2322417698664521728",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688738554",
      "createLocaltime": "2019-08-13 09:32:18",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 0,
      "state": 6,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417676665921536",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688735932",
      "createLocaltime": "2019-08-13 09:32:15",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 0,
      "state": 6,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417636630765568",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688731159",
      "createLocaltime": "2019-08-13 09:32:11",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 30,
      "pendingTtl": 100,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417537678745600",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688719363",
      "createLocaltime": "2019-08-13 09:31:59",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    },
    {
      "commandId": "2322417518334615552",
      "orgId": "yourOrgId",
      "productKey": "yourProductKey",
      "deviceKey": "yourDeviceKey",
      "assetId": "yourAssetId",
      "createTime": "1565688717057",
      "createLocaltime": "2019-08-13 09:31:57",
      "commandType": 1,
      "commandName": {
        "defaultValue": "Int_value",
        "i18nValue": {
          "en_US": "Int_value"
        }
      },
      "timeout": 10,
      "pendingTtl": 600,
      "state": 2,
      "tslIdentifier": "Int_value",
      "inputData": 111,
      "outputData": null
    }
  ],
  "pagination": {
    "sortedBy": [
      {
        "field": "createDate",
        "order": "DESC"
      }
    ],
    "pageNo": 1,
    "pageSize": 5,
    "totalSize": 6
  }
}

Java SDK 调用示例

package com.envisioniot.enos.api.sample.connect_service.command;

import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.api.common.constant.request.Pagination;
import com.envisioniot.enos.connect_service.v2_1.service.SearchCommandRequest;
import com.envisioniot.enos.connect_service.v2_1.service.SearchCommandResponse;

public class SearchCommand {

    public static void main(String[] args) {
        String accessKey = "AccessKey of your APP";
        String secretKey = "SecretKey of your APP";
        String serverUrl = "https://{apigw-address}";

        String orgId = "yourOrgId";
        String productKey = "yourProdctKey";
        String deviceKey = "yourDeviceKey";

        SearchCommandRequest request = new SearchCommandRequest();
        request.setOrgId(orgId);
        request.setProductKey(productKey);
        request.setDeviceKey(deviceKey);
        request.setExpression("commandName.zh_CN like \"Int_value\" AND createTime >= \"2019-08-13 09:00:00\"");
        request.setPagination(new Pagination(5, 1, null));
        SearchCommandResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                .url(serverUrl)
                .getResponse(request, SearchCommandResponse.class);
    }
}