Get Asset Generic Data¶
获取指定设备的指定测点在某段时间内通用类型的数据。
操作权限¶
需授权的资源 |
所需操作权限 |
---|---|
资产 |
Read |
有关各资源及其对应的权限,参考 策略,角色,与权限>>
请求格式¶
POST https://{apigw-address}/tsdb-service/v2.1/generic
请求参数(URI)¶
名称 |
位置(Path/Query) |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|---|
orgId |
Query |
必需 |
String |
资产所属的组织ID。如何获取orgId信息>> |
请求参数(Body)¶
名称 |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|
modelId |
可选 |
String |
资产所属模型ID。如何获取modelId信息>> |
assetIds |
必需 |
String |
资产ID,支持查询多个资产,多个资产ID之间用英文逗号隔开。如何获取Asset ID信息>> |
pointIds |
必需 |
String |
资产测点,支持多测点查询,各个测点间用英文逗号隔开。如何获取pointId信息>> |
startTime |
必需 |
String |
采样数据开始时间,支持local时间和UTC时间。local时间的格式为 |
endTime |
必需 |
String |
采样数据结束时间,格式必须与开始时间保持一致。 |
pageSize |
可选 |
Integer |
单次查询返回记录条数的上限,默认为1000。 |
withQuality |
可选 |
Boolean |
指定返回结果中是否包含数据质量位,true为包含,false为不包含(默认)。 |
localTimeAccuracy |
可选 |
Boolean |
指定查询结果是否包含毫秒级结果。 |
localTimeFormat |
可选 |
Integer |
指定返回数据的local时间是否包含设备时区信息。0:不包含设备时区信息;1:包含设备时区信息;默认值为0。 |
itemFormat |
可选 |
Integer |
指定返回结果中测点数据的显示格式。可选值为0,1,2,默认值为0。对每种显示格式的详细介绍,参见 Item Format 示例>> |
响应参数¶
名称 |
数据类型 |
描述 |
---|---|---|
data |
List<JSONObject> |
资产数据列表。单设备单点的返回数据按时间升序排列。详见 items |
items¶
示例¶
{
"assetId": "4DXYH7nS",
"timestamp": 1560249312446,
"opentsdb_generic_point": 1.1236,
"localtime": "2019-06-11 18:35:12",
"quality": "0"
}
参数¶
名称 |
数据类型 |
描述 |
---|---|---|
assetId |
String |
资产ID。 |
timestamp |
Long |
数据时间戳,UNIX时间,精确到秒。 |
pointId |
Double |
此参数是变量,在返回数据中显示为传入测点的标识符与查询到的测点数据。 |
localtime |
String |
数据本地时间标记,精确到秒。返回结果是否包含设备时区信息,由 |
quality |
String |
测点数据的质量位信息。 |
错误码¶
有关错误码的描述,参见 通用错误码。
示例 1¶
请求示例¶
Local时间格式:
url: https://{apigw-address}/tsdb-service/v2.1/generic?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "Ps4PViva,isj8Lj3U",
"pointIds": "generic_point",
"startTime": "2020-04-20 00:00:00",
"endTime": "2020-04-21 00:00:00",
"pageSize": 10,
"localTimeAccuracy": "false",
"localTimeFormat": 1,
"itemFormat": 0
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "Ps4PViva",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123
},
{
"assetId": "isj8Lj3U",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123
}
]
}
}
示例 2¶
请求示例¶
UTC时间格式:
url: https://{apigw-address}/tsdb-service/v2.1/generic?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "Ps4PViva,isj8Lj3U",
"pointIds": "generic_point",
"startTime": "2020-04-20T00:00:00+08:00",
"endTime": "2020-04-21T00:00:00+08:00",
"pageSize": 10,
"localTimeAccuracy": "false",
"localTimeFormat": 1,
"itemFormat": 0
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "Ps4PViva",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123
},
{
"assetId": "isj8Lj3U",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123
}
]
}
}
示例 3¶
请求示例¶
带数据质量位的查询:
url: https://{apigw-address}/tsdb-service/v2.1/generic?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "Ps4PViva,isj8Lj3U",
"pointIds": "generic_point",
"startTime": "2020-04-20T00:00:00+08:00",
"endTime": "2020-04-21T00:00:00+08:00",
"pageSize": 10,
"localTimeAccuracy": "false",
"localTimeFormat": 1,
"itemFormat": 0,
"withQuality": "true"
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "Ps4PViva",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123,
"quality": "0"
},
{
"assetId": "isj8Lj3U",
"timestamp": 1587312000000,
"localtime": "2020-04-20T00:00:00+08:00",
"generic_point": 3.123,
"quality": "0"
}
]
}
}
Java SDK调用示例¶
import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import org.junit.Before;
import org.junit.Test;
public class Sample {
private static final String API_Gateway_URL = "https://{domain_url}";
private Poseidon poseidon;
private static class Request extends PoseidonRequest {
public void setBodyParams(String key, Object value) {
bodyParams().put(key, value);
}
public void setMethod(String method) {
this.method = method;
}
private String method;
@Override
public String baseUri() {
return "";
}
@Override
public String method() {
return method;
}
}
@Before
public void init() {
poseidon = Poseidon.config(
PConfig.init()
.appKey("AccessKey of your APP")
.appSecret("SecretKey of your APP")
).method("POST").header("Content-Type", "application/json");
}
@Test
public void GetAssetGenericData() {
Request request = new Request();
request.setBodyParams("assetIds", "yourAssetId1,yourAssetId2");
request.setBodyParams("pointIds", "generic_point");
request.setBodyParams("startTime", "2020-04-20 00:00:00");
request.setBodyParams("endTime", "2020-04-21 00:00:00");
request.setBodyParams("pageSize", 10);
request.setBodyParams("localTimeAccuracy", false);
request.setBodyParams("localTimeFormat", 1);
request.setBodyParams("itemFormat", 0);
JSONObject response = poseidon
.url(API_Gateway_URL + "/tsdb-service/v2.1/generic")
.queryParam("orgId", "yourOrgId")
.getResponse(request, JSONObject.class);
System.out.println(response);
}
}