Get Asset Raw Data by Time Range¶
获取指定设备的指定测点(支持多设备多测点)在某段时间内的历史数据(包括AI原始数据、AI分钟级归一化数据、DI数据、PI数据、和通用数据类型)。
操作权限¶
需授权的资源 |
所需操作权限 |
---|---|
资产 |
Read |
有关各资源及其对应的权限,参考 策略,角色,与权限>>
请求格式¶
POST https://{apigw-address}/tsdb-service/v2.1/raw
请求参数(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。 |
orderBy |
可选 |
String |
指定返回结果按照某字段排序,目前支持按 |
withQuality |
可选 |
Boolean |
指定返回结果中是否包含数据质量位,true为包含,反之则不包含。 |
localTimeAccuracy |
可选 |
Boolean |
指定查询结果是否包含毫秒级结果。 |
localTimeFormat |
可选 |
Integer |
指定返回数据的local时间是否包含设备时区信息。0:不包含设备时区信息;1:包含设备时区信息;默认值为0。 |
itemFormat |
可选 |
Integer |
指定返回结果中测点数据的显示格式。可选值为0,1,2,默认值为0。对每种显示格式的详细介绍,参见 Item Format 示例>> |
boundaryType |
可选 |
String |
若测点已配置数据压缩存储,指定查询的测点数据类型。可选值为: |
interval |
可选 |
Integer |
当 |
interpolation |
可选 |
String |
当 |
type |
可选 |
String |
指定查询测点数据的存储类型。可选值为: |
响应参数¶
名称 |
数据类型 |
描述 |
---|---|---|
data |
List<JSONObject> |
资产数据列表。单设备单点的返回数据按时间升序排列。详见 items |
items¶
示例¶
{
"assetId": "yourAssetId",
"timestamp": 1560249312446,
"yourPointId": 1.1236,
"localtime": "2019-06-11 18:35:12",
"quality": null
}
参数¶
名称 |
数据类型 |
描述 |
---|---|---|
assetId |
String |
资产ID。 |
timestamp |
Long |
数据时间戳,UNIX时间,精确到秒。 |
pointId |
Double |
此参数是变量,在返回数据中显示为传入测点的标识符与查询到的测点数据。 |
localtime |
String |
数据本地时间标记,精确到秒。返回结果是否包含设备时区信息,由 |
quality |
Integer |
数据质量位。 |
错误码¶
有关错误码的描述,参见 通用错误码。
代码示例 1¶
请求示例¶
Local时间格式:
url: https://{apigw-address}/tsdb-service/v2.1/raw?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "yourAssetId",
"pointIds": "yourPointId1,yourPointId2",
"startTime": "2020-04-20 00:00:00",
"endTime": "2020-04-21 00:00:00",
"pageSize": 10,
"withQuality": false,
"localTimeAccuracy": false,
"localTimeFormat": 1,
"itemFormat": 0
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "yourAssetId",
"timestamp": 1587312000000,
"yourPointId1": 1.1236,
"localtime": "2020-04-20T00:00:00+08:00"
},
{
"assetId": "yourAssetId",
"timestamp": 1587312000000,
"yourPointId2": 578,
"localtime": "2020-04-20T00:00:00+08:00"
}
]
}
}
代码示例 2¶
请求示例¶
UTC时间格式:
url: https://{apigw-address}/tsdb-service/v2.1/raw?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "yourAssetId1,yourAssetId2",
"pointIds": "yourPointId1,yourPointId2",
"startTime": "2020-04-20T00:00:00+08:00",
"endTime": "2020-04-21T00:00:00+08:00",
"pageSize": 10,
"withQuality": false,
"localTimeAccuracy": true,
"localTimeFormat": 1,
"itemFormat": 0
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "yourAssetID1",
"timestamp": 1587312000000,
"yourPointId1": 1.1236,
"localtime": "2020-04-20T00:00:00+08:00"
},
{
"assetId": "yourAssetId1",
"timestamp": 1587312000000,
"yourPointId2": 578,
"localtime": "2020-04-20T00:00:00+08:00"
}
]
}
}
代码示例 3¶
请求示例¶
带数据质量位的查询:
url: https://{apigw-address}/tsdb-service/v2.1/raw?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "yourAssetIds",
"pointIds": "yourPointId1,yourPointId2",
"startTime": "2020-04-20T00:00:00+08:00",
"endTime": "2020-04-21T00:00:00+08:00",
"pageSize": 10,
"withQuality": true,
"localTimeAccuracy": false,
"localTimeFormat": 1,
"itemFormat": 0
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "yourAssetId",
"timestamp": 1587312000000,
"yourPointId1": 1.1236,
"localtime": "2020-04-20T00:00:00+08:00",
"quality": 0
},
{
"assetId": "yourAssetId",
"timestamp": 1587312000000,
"yourPointId2": 578,
"localtime": "2020-04-20T00:00:00+08:00",
"quality": 0
}
]
}
}
代码示例 4¶
请求示例¶
查询原始压缩数据,并返回查询起止时间边界前后的数据。
url: https://{apigw-address}/tsdb-service/v2.1/raw?orgId=yourOrgId
method: POST
Content-Type: application/json
requestBody:
{
"assetIds": "yourAssetIds",
"pointIds": "yourPointIds",
"startTime": "2020-08-28T11:33:00+08:00",
"endTime": "2020-08-28T11:35:00+08:00",
"boundaryType", "outside"
}
返回示例¶
{
"code": 0,
"msg": "OK",
"submsg": null,
"data": {
"items": [
{
"assetId": "yourAssetId",
"timestamp": 1598585576906,
"yourPointId": 0.8807087,
"localtime": "2020-08-28 11:32:56"
},
{
"assetId": "yourAssetId",
"timestamp": 1598585587039,
"yourPointId": 0.26798052,
"localtime": "2020-08-28 11:33:07"
},
{
"assetId": "yourAssetId",
"timestamp": 1598585597125,
"yourPointId": 0.65514636,
"localtime": "2020-08-28 11:33:17"
},
{
"assetId": "yourAssetId",
"timestamp": 1598585708013,
"yourPointId": 0.342161,
"localtime": "2020-08-28 11:35:08"
}
]
}
}
可选参数结果示例¶
对于可选参数 boundaryType、interval、interpolation,填入不同的可选值,将产生不同的返回数据。下文用表格形式对以下几种情况作简单示例。
若原始数据为:
2021-11-01 00:27:00 677.0 2021-11-01 00:37:00 728.0 2021-11-01 00:47:00 1228.0
查询条件填写 00:35:00 到 00:40:00
boundaryType |
interval |
interpolation |
返回数据 |
---|---|---|---|
inside |
/ |
/ |
2021-11-01 00:37:00 728.0 |
outside |
/ |
/ |
2021-11-01 00:27:00 677.0 |
interpolated |
/ |
/ |
2021-11-01 00:35:00 677.0 |
sample |
1min |
linear |
2021-11-01 00:35:00 717.8 |
sample |
1min |
previous |
2021-11-01 00:35:00 677.0 |
sample |
1min |
after |
2021-11-01 00:35:00 728.0 |
sample |
1min |
near |
2021-11-01 00:35:00 728.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;
public class GetAssetRawDataByTimeRange {
private static final String API_Gateway_URL = "https://{apigw-address}";
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;
}
}
public static void main(String[] args) {
//1.在EnOS管理门户的左边导航栏中点击应用注册。
//2.点击需调用API的应用,查看基本信息中的AccessKey和SecretKey
Poseidon poseidon = Poseidon.config(
PConfig.init()
.appKey("AccessKey of your APP")
.appSecret("SecretKey of your APP")
).method("POST").header("Content-Type", "application/json");
Request request = new Request();
request.setBodyParams("assetIds", "yourAssetIds");
request.setBodyParams("pointIds", "yourPointId1,yourPointId2");
request.setBodyParams("startTime", "2020-04-20 00:00:00");
request.setBodyParams("endTime", "2020-04-21 00:00:00");
request.setBodyParams("pageSize", 10);
request.setBodyParams("withQuality", true);
request.setBodyParams("localTimeAccuracy", false);
request.setBodyParams("localTimeFormat", 1);
request.setBodyParams("itemFormat", 0);
request.setBodyParams("boundaryType", "inside");
request.setBodyParams("type", "ai");
JSONObject response = poseidon
.url(API_Gateway_URL + "/tsdb-service/v2.1/raw")
.queryParam("orgId", "yourOrgId")
.getResponse(request, JSONObject.class);
System.out.println(response);
}
}