文档

应用设备管理服务API

更新时间:
一键部署

1. 概述

提供应用下设备列表、设备属性及状态获取,设备属性设置及设备服务调用。

2. 接口定义

2.1设备查询

2.1.1 批量获取应用的产品所有设备属性状态

路径

/app/thing/properties/batch/get

版本号

1.0.1

协议

HTTPS

请求方法

POST

授权类型

app签名

超时时间

10000

请求参数

名称

类型

是否必选

描述

productKey

String

产品pk

pageNo

Integer

当前页

pageSize

Integer

页面大小

lpInstanceId

String

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

data:

名称

类型

描述

total

Integer

总页数

pageNo

Integer

当前页

pageSize

Integer

每页大小

data

SimpleDeviceInfoAndPropert

分页数据对象列表

分页数据对象 SimpleDeviceInfoAndPropert:

名称

类型

描述

productName

String

产品名称

productKey

String

产品pk

deviceName

String

设备名称

nodeType

Integer

设备节点

status

String

设备状态

activeTime

String

设备激活时间

lastOnlineTime

String

设备最好一次上线时间

createTime

String

设备创建时间

childDeviceCount

Long

自设备连接数

iotId

String

设备iotId

rangeQueryDTO

DeviceStatusDTO

设备属性快照列表

设备属性快照列表 DeviceStatusDTO:

名称

类型

描述

iotId

String

设备iotId

batchId

String

设备上报的标示。

可以批量上报,同一个批次上报的这个batchid一样

attribute

String

设备属性

group

Integer

设备分组

value

String

属性值

gmtModified

String

修改时间

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.1");
// 设置参数
request.putParam("productKey","value1");
request.putParam("pageNo","value2");
request.putParam("pageSize","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/properties/batch/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
    "code":200,
    "data":{
        "total":1,
        "data":[
            {
                "activeTime":"2019-12-12 20:13:35",
                "nodeType":0,
                "productKey":"a17nEF9qLYJ",
                "deviceName":"mIwfRzXY9wLpRFz5RfJJ",
                "utcCreateTime":"2019-12-04T09:00:27.000Z",
                "productName":"studio体验产品",
                "utcActiveTime":"2019-12-12T12:13:35.164Z",
                "utcLastOnlineTime":"2019-12-12T12:13:35.164Z",
                "iotId":"mIwfRzXY9wLpRFz5RfJJ000101",
                "createTime":"2019-12-04 17:00:27",
                "lastOnlineTime":"2019-12-12 20:13:35",
                "rangeQueryDTO":[
                    {
                        "identifier":"LightStatus",
                        "unit":"",
                        "dataType":"bool",
                        "name":"工作状态"
                    },
                    {
                        "identifier":"LightAdjustLevel",
                        "unit":"%",
                        "dataType":"int",
                        "name":"调光等级"
                    },
                    {
                        "identifier":"LightVolt",
                        "unit":"V",
                        "dataType":"float",
                        "name":"工作电压"
                    },
                    {
                        "identifier":"LightCurrent",
                        "unit":"A",
                        "dataType":"float",
                        "name":"工作电流"
                    },
                    {
                        "identifier":"ActivePower",
                        "unit":"W",
                        "dataType":"float",
                        "name":"有功功率值"
                    },
                    {
                        "identifier":"PowerRatio",
                        "unit":"pF",
                        "dataType":"float",
                        "name":"功率因数"
                    },
                    {
                        "identifier":"PowerConsumption",
                        "unit":"kW·h",
                        "dataType":"float",
                        "name":"用电量"
                    },
                    {
                        "identifier":"DrainVoltage",
                        "unit":"V",
                        "dataType":"float",
                        "name":"漏电压"
                    },
                    {
                        "identifier":"TiltValue",
                        "unit":"°",
                        "dataType":"int",
                        "name":"倾斜角度值"
                    },
                    {
                        "identifier":"ErrorPowerThreshold",
                        "unit":"W",
                        "dataType":"int",
                        "name":"故障功率门限"
                    },
                    {
                        "identifier":"ErrorCurrentThreshold",
                        "unit":"A",
                        "dataType":"float",
                        "name":"故障电流门限"
                    },
                    {
                        "identifier":"TiltThreshold",
                        "unit":"°",
                        "dataType":"int",
                        "name":"倾斜阈值"
                    },
                    {
                        "identifier":"UnderVoltThreshold",
                        "unit":"V",
                        "dataType":"int",
                        "name":"欠压阈值"
                    },
                    {
                        "identifier":"OverCurrentThreshold",
                        "unit":"A",
                        "dataType":"int",
                        "name":"过流阈值"
                    },
                    {
                        "identifier":"OverVoltThreshold",
                        "unit":"V",
                        "dataType":"int",
                        "name":"过压阈值"
                    },
                    {
                        "identifier":"LightErrorEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"灯具故障使能"
                    },
                    {
                        "identifier":"OverCurrentEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"过流告警使能"
                    },
                    {
                        "identifier":"OverVoltEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"过压告警使能"
                    },
                    {
                        "identifier":"UnderVoltEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"欠压告警使能"
                    },
                    {
                        "identifier":"LeakageEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"漏电告警使能"
                    },
                    {
                        "identifier":"OverTiltEnable",
                        "unit":"",
                        "dataType":"bool",
                        "name":"倾斜告警使能"
                    },
                    {
                        "identifier":"LampError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"灯具故障告警"
                    },
                    {
                        "identifier":"OverCurrentError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"过流告警"
                    },
                    {
                        "identifier":"OverVoltError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"过压告警"
                    },
                    {
                        "identifier":"UnderVoltError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"欠压告警"
                    },
                    {
                        "identifier":"OverTiltError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"倾斜告警"
                    },
                    {
                        "identifier":"LeakageError",
                        "unit":"",
                        "dataType":"bool",
                        "name":"漏电告警"
                    },
                    {
                        "identifier":"GeoLocation",
                        "unit":"",
                        "dataType":"struct",
                        "name":"地理位置"
                    }
                ],
                "status":"OFFLINE"
            }
        ],
        "pageNo":1,
        "pageSize":20
    },
    "message":"success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

2.1.2 获取物的属性timeline数据

路径

/app/thing/property/timeline/get

版本号

1.0.4

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

identifier

String

设备属性标识符

start

Long

开始时间

end

Long

结束时间

pageSize

Integer

单次查询最大条数

ordered

Boolean

查询顺序,true-顺序查询,false-倒序查询

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

响应结果 data:

名称

类型

描述

timestamp

Long

时间戳

items

ThingEventDTO

设备的事件数据列表

设备的事件数据列表 ThingEventDTO:

名称

类型

描述

iotId

String

物的ID

eventCode

String

事件 code

eventName

String

事件名称

eventType

String

事件类型

timestamp

Long

时间戳

eventBody

Object

事件 body

batchId

String

批次ID

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.4");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("identifier","value4");
request.putParam("start","value5");
request.putParam("end","value6");
request.putParam("pageSize","value7");
request.putParam("ordered","value8");
request.putParam("lpInstanceId","value9");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/property/timeline/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
  "code": 200,
  "data": {
    "items": [
      {
        "batchId": "364f191a24c54f4ebf8254ee6945cca4",
        "data": 48.2,
        "property": "Humidity",
        "timestamp": 1604801094028
      },
      {
        "batchId": "8e70129623a04bc18bc152e6f95a50cb",
        "data": 48.2,
        "property": "Humidity",
        "timestamp": 1604808221032
      }
    ],
    "timestamp": 1604808221032
  },
  "message": "success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

2.1.3 批量获取应用的设备信息

路径

/app/thing/info/list/get

版本号

1.4.1

协议

HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotIds

List<String>

设备ID列表

productKey

String

设备的产品pk,需要与设备名称列表组合使用

deviceName

List<String>

设备名称列表,需要与设备的产品pk组合使用

appId

字符串

应用ID。传入应用ID时,设备ID、设备的产品pk、设备名称无需传递

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

List<DeviceDTO>

响应结果:设备属性列表

设备属性列表 DeviceDTO:

名称

类型

描述

gmtCreate

Date

设备创建时间

gmtModified

Date

设备修改时间

iotId

String

设备ID

name

String

设备名称

deviceSecret

String

设备sk

productKey

String

产品pk

mac

String

设备物理地址

region

String

设备区域

status

int

设备状态

activeTime

Date

设备激活时间

netAddress

String

设备网络地址

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.4.1");
// 设置参数
request.putParam("iotIds","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("appId","value4");
request.putParam("lpInstanceId","value5");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/info/list/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
 "code": 200,
 "data": [{
  "gmtModified": 1564971320000,
  "activeTime": 1576214088740,
  "deviceKey": "ErMmUJAE6nRduVjQ7wi9",
  "productKey": "a1QcurjTB1h",
  "statusLast": 3,
  "gmtCreate": 1564971320000,
  "deviceSecret": "7pRFl0XfRmFldKk4NzfGng3y3B3t1mF5",
  "iotId": "ErMmUJAE6nRduVjQ7wi9000101",
  "name": "wjgT_0034",
  "thingType": "DEVICE",
  "region": "cn-hangzhou",
  "rbacTenantId": "87F2BEFA5D9B45B9AE2CD8C41AC40613",
  "status": 1
 }],
 "id": "4f3196f64a1d480bafa45e9c8006f543"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

2.1.4 获取物的基本信息

路径

/app/thing/info/get

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

字符串

物的唯一标识

productKey

字符串

物的产品标识

deviceName

字符串

物的名称

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果:

设备属性 DeviceDTO

设备属性 DeviceDTO:

名称

类型

描述

gmtCreate

Date

设备创建时间

gmtModified

Date

设备修改时间

iotId

String

设备ID

name

String

设备名称

deviceSecret

String

设备sk

productKey

String

产品pk

mac

String

设备物理地址

region

String

设备区域

status

int

设备状态

activeTime

Date

设备激活时间

netAddress

String

设备网络地址

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/info/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
    "code":200,
    "data":{
        "gmtModified":1607334316000,
        "deviceKey":"1g84blz9FRQOrlqB0OT1",
        "productKey":"a1jemBywtIo",
        "statusLast":0,
        "gmtCreate":1607334316000,
        "productName":"apigatewaytest",
        "iotId":"1g84blz9FRQOrlqB0OT1000101",
        "deviceSecret":"683c84dc5eb88705bd5cf4fbf65f6802",
        "name":"apigatewaydevice",
        "nickname":"apigatewaydevice",
        "thingType":"DEVICE",
        "region":"cn-hangzhou",
        "rbacTenantId":"87F2BEFA5D9B45B9AE2CD8C41AC40613",
        "status":0
    },
    "id":"244bc36c-5fd0-4fec-bd1a-b57f38db3769"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止"
}

错误码

错误码

错误信息

错误描述

40062

not authorization query device

没有权限查询设备

2.1.5 根据设备证书(ProductKey、DeviceName、DeviceSecret)获取物的模板

路径

/app/thing/dsl/get

版本号

1.0.1

协议

HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

lpInstanceId

String

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

json格式物模版信息TSL

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.1");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/dsl/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
 "code": 200,
 "data": "{\"schema\":\"https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json\",\"profile\":{\"productKey\":\"a1PHv5Xn2xX\",\"deviceName\":\"xixi\"},\"link\":\"/sys/a1PHv5Xn2xX/xixi/thing/\",\"services\":[{\"outputData\":[],\"identifier\":\"set\",\"inputData\":[{\"identifier\":\"CurtainOperation\",\"dataType\":{\"specs\":{\"0\":\"关窗帘\",\"1\":\"开\",\"2\":\"暂停\"},\"type\":\"enum\"},\"name\":\"模式\"},{\"identifier\":\"PowerSwitch\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"电源开关\"},{\"identifier\":\"CurtainPosition\",\"dataType\":{\"specs\":{\"unit\":\"%\",\"min\":\"0\",\"unitName\":\"百分比\",\"max\":\"100\",\"step\":\"1\"},\"type\":\"int\"},\"name\":\"位置\"},{\"identifier\":\"LocalTimer\",\"dataType\":{\"specs\":{\"item\":{\"specs\":[{\"identifier\":\"Timer\",\"dataType\":{\"specs\":{\"length\":\"255\"},\"type\":\"text\"},\"name\":\"定时时间\"},{\"identifier\":\"Enable\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"启用\"},{\"identifier\":\"IsValid\",\"dataType\":{\"specs\":{\"0\":\"无效\",\"1\":\"有效\"},\"type\":\"bool\"},\"name\":\"可执行\"},{\"identifier\":\"Targets\",\"dataType\":{\"specs\":{\"length\":\"2048\"},\"type\":\"text\"},\"name\":\"定时动作\"}],\"type\":\"struct\"},\"size\":\"109\"},\"type\":\"array\"},\"name\":\"本地定时\"}],\"method\":\"thing.service.property.set\",\"name\":\"set\",\"required\":true,\"callType\":\"async\",\"desc\":\"属性设置\"},{\"outputData\":[{\"identifier\":\"CurtainOperation\",\"dataType\":{\"specs\":{\"0\":\"关窗帘\",\"1\":\"开\",\"2\":\"暂停\"},\"type\":\"enum\"},\"name\":\"模式\"},{\"identifier\":\"PowerSwitch\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"电源开关\"},{\"identifier\":\"CurtainPosition\",\"dataType\":{\"specs\":{\"unit\":\"%\",\"min\":\"0\",\"unitName\":\"百分比\",\"max\":\"100\",\"step\":\"1\"},\"type\":\"int\"},\"name\":\"位置\"},{\"identifier\":\"LocalTimer\",\"dataType\":{\"specs\":{\"item\":{\"specs\":[{\"identifier\":\"Timer\",\"dataType\":{\"specs\":{\"length\":\"255\"},\"type\":\"text\"},\"name\":\"定时时间\"},{\"identifier\":\"Enable\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"启用\"},{\"identifier\":\"IsValid\",\"dataType\":{\"specs\":{\"0\":\"无效\",\"1\":\"有效\"},\"type\":\"bool\"},\"name\":\"可执行\"},{\"identifier\":\"Targets\",\"dataType\":{\"specs\":{\"length\":\"2048\"},\"type\":\"text\"},\"name\":\"定时动作\"}],\"type\":\"struct\"},\"size\":\"109\"},\"type\":\"array\"},\"name\":\"本地定时\"}],\"identifier\":\"get\",\"inputData\":[\"CurtainOperation\",\"PowerSwitch\",\"CurtainPosition\",\"LocalTimer\"],\"method\":\"thing.service.property.get\",\"name\":\"get\",\"required\":true,\"callType\":\"async\",\"desc\":\"属性获取\"}],\"properties\":[{\"identifier\":\"CurtainOperation\",\"dataType\":{\"specs\":{\"0\":\"关窗帘\",\"1\":\"开\",\"2\":\"暂停\"},\"type\":\"enum\"},\"name\":\"模式\",\"accessMode\":\"rw\",\"required\":false},{\"identifier\":\"PowerSwitch\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"电源开关\",\"accessMode\":\"rw\",\"required\":false},{\"identifier\":\"CurtainPosition\",\"dataType\":{\"specs\":{\"unit\":\"%\",\"min\":\"0\",\"unitName\":\"百分比\",\"max\":\"100\",\"step\":\"1\"},\"type\":\"int\"},\"name\":\"位置\",\"accessMode\":\"rw\",\"required\":false},{\"identifier\":\"LocalTimer\",\"dataType\":{\"specs\":{\"item\":{\"specs\":[{\"identifier\":\"Timer\",\"dataType\":{\"specs\":{\"length\":\"255\"},\"type\":\"text\"},\"name\":\"定时时间\"},{\"identifier\":\"Enable\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"启用\"},{\"identifier\":\"IsValid\",\"dataType\":{\"specs\":{\"0\":\"无效\",\"1\":\"有效\"},\"type\":\"bool\"},\"name\":\"可执行\"},{\"identifier\":\"Targets\",\"dataType\":{\"specs\":{\"length\":\"2048\"},\"type\":\"text\"},\"name\":\"定时动作\"}],\"type\":\"struct\"},\"size\":\"109\"},\"type\":\"array\"},\"name\":\"本地定时\",\"accessMode\":\"rw\",\"required\":true,\"desc\":\"用于为设备配置本地控制,其中前三个参数必选,其它参数自主填写,用于表示该产品哪些功能作为“可被本地控制的功能”,这些参数请和设备的标准功能保持一致。\"}],\"events\":[{\"outputData\":[{\"identifier\":\"CurtainOperation\",\"dataType\":{\"specs\":{\"0\":\"关窗帘\",\"1\":\"开\",\"2\":\"暂停\"},\"type\":\"enum\"},\"name\":\"模式\"},{\"identifier\":\"PowerSwitch\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"电源开关\"},{\"identifier\":\"CurtainPosition\",\"dataType\":{\"specs\":{\"unit\":\"%\",\"min\":\"0\",\"unitName\":\"百分比\",\"max\":\"100\",\"step\":\"1\"},\"type\":\"int\"},\"name\":\"位置\"},{\"identifier\":\"LocalTimer\",\"dataType\":{\"specs\":{\"item\":{\"specs\":[{\"identifier\":\"Timer\",\"dataType\":{\"specs\":{\"length\":\"255\"},\"type\":\"text\"},\"name\":\"定时时间\"},{\"identifier\":\"Enable\",\"dataType\":{\"specs\":{\"0\":\"关\",\"1\":\"开\"},\"type\":\"bool\"},\"name\":\"启用\"},{\"identifier\":\"IsValid\",\"dataType\":{\"specs\":{\"0\":\"无效\",\"1\":\"有效\"},\"type\":\"bool\"},\"name\":\"可执行\"},{\"identifier\":\"Targets\",\"dataType\":{\"specs\":{\"length\":\"2048\"},\"type\":\"text\"},\"name\":\"定时动作\"}],\"type\":\"struct\"},\"size\":\"109\"},\"type\":\"array\"},\"name\":\"本地定时\"}],\"identifier\":\"post\",\"method\":\"thing.event.property.post\",\"name\":\"post\",\"type\":\"info\",\"required\":true,\"desc\":\"属性上报\"}]}",
 "message": "success"
}

2.1.6 获取物的服务记录

路径

/app/thing/service/data/get

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

identifier

String

服务标识符

start

String

开始时间

end

String

结束时间

pageSize

Integer

单次查询最大条数

ordered

String

查询顺序,true-顺序查询,false-倒序查询

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

响应结果 data:

名称

类型

描述

nextTime

Long

最近调用时间戳

data

List<ServiceInfoDTO>

服务数据列表

服务数据列表 ServiceInfoDTO:

名称

类型

描述

identifier

String

服务标识

name

String

服务名称

time

Long

服务时间

inputData

String

输入参数

outputData

String

输出参数

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("identifier","value4");
request.putParam("start","value5");
request.putParam("end","value6");
request.putParam("pageSize","value7");
request.putParam("ordered","value8");
request.putParam("lpInstanceId","value9");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/service/data/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
  "code": 200,
  "data": {
    "list": [
      {
        "identifier": "testServiceSync",
        "inputData": "{\"structArgs\":{\"structchildINT62005ae\":50,\"structchildDOUBLE6d967d2\":50.22,\"structchildDATEaec2a80\":\"1605786342845\",\"structchildBOOLa05d374\":0,\"structchildFLOAT76c6d83\":50.11,\"structchildTEXT710c059\":\"xiaoyuershi\",\"structchildENUMe811671\":1},\"enumArgs\":1,\"boolArgs\":0,\"floatArgs\":50.11,\"intArgs\":10,\"dateArgs\":\"1605786342845\",\"doubleArgs\":50.22,\"arrayArgs\":[1,2,3],\"textArgs\":\"你好helloworld\"}",
        "name": "testServiceSyncName",
        "outputData": "{\"code\":200,\"data\":{\"structArgs\":{\"structchildINT62005ae\":50,\"structchildDOUBLE6d967d2\":50.22,\"structchildDATEaec2a80\":\"1605786342845\",\"structchildBOOLa05d374\":0,\"structchildFLOAT76c6d83\":50.11,\"structchildTEXT710c059\":\"xiaoyuershi\",\"structchildENUMe811671\":1},\"enumArgs\":1,\"boolArgs\":0,\"floatArgs\":50.11,\"intArgs\":10,\"dateArgs\":\"1605786342845\",\"doubleArgs\":50.22,\"arrayArgs\":[1,2,3],\"textArgs\":\"你好helloworld\"},\"id\":\"Akeg8vmMdQ\",\"message\":\"success\",\"version\":\"1.0\"}",
        "time": 1605786348669
      }
    ],
    "nextTime": 1605786348670,
    "nextValid": false
  },
  "message": "success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.1.7 获取物的连接状态

路径

/app/thing/status/get

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

返回结果 data:

名称

类型

描述

deviceName

String

设备名称

status

Integer

设备状态

0 - 未激活, 1 - 在线, 3 - 离线, 8 - 禁用

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/status/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
    "code":200,
    "data":{
        "deviceName":"apigatewaydevice",
        "status":1
    },
    "id":"be4cb9d0-5d71-4e44-bc10-866eb718731c"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.1.8 获取物的拓扑关系

路径

/app/thing/topo/get

版本号

1.0.0

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

pageNo

Integer

页面ID

pageSize

Integer

分页大小

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

响应结果 data:

名称

类型

描述

total

整型

总页数

pageNo

整型

当前页

pageSize

整型

每页大小

data

SimpleDeviceDTO

简单的设备信息对象,只包含设备ID和设备证书(ProductKey、DeviceName、DeviceSecret)信息

SimpleDeviceDTO:

名称

类型

描述

iotId

String

设备ID

deviceSecret

String

设备名称

deviceSecret

String

设备sk

productKey

String

产品pk

2.1.9 获取物的标签列表

路径

/app/thing/prop/get

版本号

1.0.1

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

props

String

设备标签属性,json String结构

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.1");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/prop/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

2.1.10 获取物的事件timeline数据

路径

/app/thing/event/timeline/get

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

identifier

String

事件标识符

eventType

String

事件类型

start

Long

timeline起始时间

end

Long

timeline结束时间

pageSize

Integer

分页大小

ordered

Boolean

顺序(true);逆序(false)查询

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

响应结果 data:

名称

类型

描述

timestamp

Long

items

ThingEventDTO

事件数据

事件数据 ThingEventDTO:

名称

类型

描述

iotId

String

物的ID

eventCode

String

事件 code

eventName

String

事件名称

eventType

String

事件类型

timestamp

Long

事件发生时间

eventBody

Object

事件Body

batchId

String

批次ID

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("identifier","value4");
request.putParam("eventType","value5");
request.putParam("start","value6");
request.putParam("end","value7");
request.putParam("pageSize","value8");
request.putParam("ordered","value9");
request.putParam("lpInstanceId","value10");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/event/timeline/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
    "code":200,
    "data":{
        "items":[{
            "batchId":"c0c0eab124bc4231b25aee934dfa234c",
            "eventBody":{
                "boolArgs":0,
                "floatArgs":1.23,
                "intArgs":4
            },
            "eventCode":"testAlertEvent",
            "eventName":"testAlertEventName",
            "eventType":"alert",
            "iotId":"1gHTxTa1NdKXl6wGE3jx000000",
            "timestamp":1605775253666
        }],
        "timestamp":1605775253666
    },
    "message":"success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.1.11 批量获取物的状态

路径

/app/thing/status/batch/get

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

productKey

String

物的产品标识

deviceNames

List<String>

物的名称列表,一次最多支持查询10个

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Integer

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

List<ThingStatusInfoDTO>

设备状态信息列表

设备状态信息列表 ThingStatusInfoDTO:

名称

类型

描述

deviceName

String

设备名称

status

Integer

设备状态

0 - 未激活, 1 - 在线, 3 - 离线, 8 - 禁用

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("productKey","value1");
request.putParam("deviceNames","value2");
request.putParam("lpInstanceId","value3");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/status/batch/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
  "code": 200,
  "data": [{
    "deviceName": "apigatewaydevice",
    "status": 0
  }],
  "id": "ed663083-c963-49e4-aa36-f0a6d62a6a23"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.1.12 查询应用物的列表

路径

/app/thing/list

版本号

1.0.4

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

tagList

JSONAarry

标签列表

pageNo

Integer

当前页,从1开始

pageSize

Integer

每页大小,最大200

productKeyList

JSONAarry

productkeylist

categoryKeyList

JSONAarry

品类列表

appId

字符串

应用ID

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

JSON

响应结果

响应结果 data:

名称

类型

描述

total

Integer

总页数

pageNo

Integer

当前页

pageSize

Integer

每页大小

data

List<SimpleDeviceInfo>

SimpleDeviceInfo:

名称

类型

描述

productName

String

产品名称

productKey

String

产品pk

deviceName

String

设备名称

nodeType

Integer

设备网络类型

status

String

设备专题

activeTime

String

设备激活时间

lastOnlineTime

String

设备最近上线时间

createTime

String

设备创建时间

childDeviceCount

Long

子设备数量

iotId

String

设备ID

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.4");
// 设置参数
request.putParam("tagList","value1");
request.putParam("pageNo","value2");
request.putParam("pageSize","value3");
request.putParam("productKeyList","value4");
request.putParam("categoryKeyList","value5");
request.putParam("appId","value6");
request.putParam("lpInstanceId","value7");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/list", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
 "code": 200,
 "data": {
  "total": 1,
  "data": [{
   "activeTime": "2019-12-13 13:14:48",
   "productKey": "a1QcurjTB1h",
   "nodeType": 0,
   "deviceName": "wjgT_0034",
   "utcCreateTime": "2019-08-05T02:15:20.000Z",
   "productName": "授权设备",
   "utcActiveTime": "2019-12-13T05:14:48.740Z",
   "utcLastOnlineTime": "2019-12-13T05:17:54.315Z",
   "iotId": "ErMmUJAE6nRduVjQ7wi9000101",
   "createTime": "2019-08-05 10:15:20",
   "lastOnlineTime": "2019-12-13 13:17:54",
   "status": "ONLINE"
  }],
  "pageNo": 1,
  "pageSize": 20
 },
 "id": "107595bf12f9465e9530850b0baf60f3"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

40063

app not exist

应用不存在

40106

saas tenant not exist

saas租户不存在

400

request error.

系统繁忙

40061

query device error

查询设备错误

2.1.13 获取物的属性

路径

/app/thing/properties/get

版本号

1.0.4

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

data

List<DeviceStatusDTO>

设备属性列表

DeviceStatusDTO:

名称

类型

描述

iotId

String

设备iotId

batchId

String

设备上报的标示。

可以批量上报,同一个批次上报的这个batchid一样

attribute

String

设备属性

group

Integer

设备分组

value

String

属性值

gmtModified

String

修改时间

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.4");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("lpInstanceId","value4");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/properties/get", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
  "code": 200,
  "data": [
    {
      "iotId": "1g84blz9FRQOrlqB0OT1000101",
      "gmtModified": 1607338094175,
      "attribute": "Humidity",
      "batchId": "c9bdb91fb7c948d2a0af68f0af96105b",
      "value": 8
    },
    {
      "iotId": "1g84blz9FRQOrlqB0OT1000101",
      "gmtModified": 1607338053955,
      "attribute": "Speed",
      "batchId": "3cc1e8c95ca3426c95f148636a189f87",
      "value": 70
    }
  ],
  "message": "success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.2设备控制

2.2.1 设置物的属性

路径

/app/thing/properties/set

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

items

JSONObject

设备属性map,包含属性key及value

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("items","value4");
request.putParam("lpInstanceId","value5");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/properties/set", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
    "code":200,
    "message":"success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

2.2.2 触发物的服务

路径

/app/thing/service/invoke

版本号

1.0.3

协议

HTTP/HTTPS

请求方法

POST

授权类型

app签名

超时时间

3000

请求参数

名称

类型

是否必选

描述

iotId

String

物的唯一标识

productKey

String

物的产品标识

deviceName

String

物的名称

args

JSONObject

服务参数

identifier

String

服务标识符

lpInstanceId

字符串

LP实例ID

返回数据

名称

类型

描述

code

Int

接口返回码。200表示成功。

message

String

调用失败时,返回的出错信息。

localizedMsg

String

本地语言的错误消息。

示例

请求示例:

// https://github.com/aliyun/iotx-api-gateway-client
IoTApiClientBuilderParams ioTApiClientBuilderParams = new IoTApiClientBuilderParams();

ioTApiClientBuilderParams.setAppKey("你的<AppKey>");
ioTApiClientBuilderParams.setAppSecret("你的<AppSecret>");

SyncApiClient syncApiClient = new SyncApiClient(ioTApiClientBuilderParams);

IoTApiRequest request = new IoTApiRequest();

// 设置请求ID
String uuid = UUID.randomUUID().toString();
String id = uuid.replace("-", "");
request.setId(id);
// 设置API版本号
request.setApiVer("1.0.3");
// 设置参数
request.putParam("iotId","value1");
request.putParam("productKey","value2");
request.putParam("deviceName","value3");
request.putParam("args","value4");
request.putParam("identifier","value5");
request.putParam("lpInstanceId","value6");
// 如果需要,设置headers
Map<String, String> headers = new HashMap<String, String>(8);
// headers.put("你的<header", "你的<value>");

// 设置请求参数域名、path、request , isHttps, headers
ApiResponse response = syncApiClient.postBody("api.link.aliyun.com", "/app/thing/service/invoke", request, true, headers);

System.out.println(
    "response code = " + response.getCode()
        + " response = " + new String(response.getBody(), "UTF-8")
        + " headers = " + response.getHeaders().toString()
);

正常返回示例:

{
  "code": 200,
  "data": {
    "data": {
      "SyncFileStatus": 0
    },
    "messageId": "854287045"
  },
  "message": "success"
}

异常返回示例:

{
    "id": "37f7e5fa-d6a5-4efe-8abf-5bf23dca6284",
    "code": 403,
    "message": "request forbidden.",
    "localizedMsg": "请求被禁止",
    "data": null
}

错误码:

错误码

错误信息

错误描述

400

request error.

系统繁忙

3. 设备消息订阅

设备数据订阅指引

  • 本页导读 (0)
文档反馈