Get Command¶
获取单个命令信息。
请求格式¶
GET https://{apigw-address}/connect-service/v2.1/commands?action=get
请求参数(URI)¶
注解
以下非必须字段中,必须提供 assetId
或 productKey
+ 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 一起使用。 |
commandId | Query | 必需 | String | 命令 ID。 |
响应参数¶
名称 | 数据类型 | 描述 |
---|---|---|
data | 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数据类型需要符合物模型的定义。 |
错误码 ¶
代码 | 描述 |
---|---|
11404 | commandId 未找到或不存在。 |
11810 | 当 Product 支持自定义数据格式时,无法将命令编码成 Product 自定义格式。 |
11888 | 设备未激活,即时命令无法发送。 |
11900 | 设备不在线,即时命令无法发送。 |
11902 | 缓存命令已达上限。 |
11904 | 命令未发送,即时命令超时。 |
11915 | 命令已发送,但是响应超时。 |
示例¶
请求示例¶
url: https://{apigw-address}/connect-service/v2.1/commands?action=get&deviceKey=yourDeviceKey&productKey=yourProductKey&commandId=yourCommandId&orgId=yourOrgId
method: GET
返回示例¶
{
"code": 0,
"msg": "OK",
"requestId": "7d863d517eae4f18a2776452eb1305bb",
"data": {
"commandId": "2242591201245044736",
"orgId": "yourOrgId",
"productKey": "yourProductKey",
"deviceKey": "yourDeviceKey",
"assetId": "yourAssetId",
"createTime": "15910899018",
"createLocalTime": "2020-06-02 17:25:01",
"commandType": 2,
"commandName": {
"defaultValue": "",
"i18nValue": {
"en_US": "test_service"
}
},
"timeout": 30,
"pendingTtl": 1000,
"state": 2,
"tslIdentifier": "test_service",
"inputData": {
"parameter_1": 1.3,
"parameter_2": 13
},
"outputData": null
}
}
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.connect_service.v2_1.service.GetCommandRequest;
import com.envisioniot.enos.connect_service.v2_1.service.GetCommandResponse;
public class GetCommand {
public static void main(String[] args) {
String appKey = "yourAppKey";
String appSecret = "yourAppSecret";
String serverUrl = "yourServerUrl";
String orgId = "yourOrgId";
String productKey = "yourProductKey";
String deviceKey = "yourDeviceKey";
String commandId = "yourCommandId";
GetCommandRequest request = new GetCommandRequest();
request.setOrgId(orgId);
request.setProductKey(productKey);
request.setDeviceKey(deviceKey);
request.setCommandId(commandId);
GetCommandResponse response = Poseidon.config(PConfig.init().appKey(appKey).appSecret(appSecret).debug())
.url(serverUrl)
.getResponse(request, GetCommandResponse.class);
}
}