Get Asset Electric Power Data

获取指定设备在某段时间内的电量数据。

操作权限

需授权的资源 所需操作权限
资产 Read

有关各资源及其对应的权限,参考 策略,角色,与权限>>

使用GET方法

请求格式

GET https://{apigw-address}/tsdb-service/v2.0/electric-power

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织ID。如何获取orgId信息>>
modelId Query 可选 String 资产所属模型ID。如何获取modelId信息>>
assetIds Query 必需 String 资产ID,支持查询多个资产,多个资产ID之间用英文逗号隔开。如何获取Asset ID信息>>
measurepointsWithLogic Query 必需 String 测点数据聚合逻辑,支持的聚合计算方式有count, avg, sum, max, min, first, last。聚合查询的时间区间为 [startTime,endTime),即聚合操作数包含 startTime 时刻的数据,但不包含 endTime 时刻的数据。格式为:函数(测点标识符),支持查询多个测点,例如:sum(pointId1),sum(pointId2)如何获取pointId信息>>
interval Query 必需 Integer 聚合算法作用的时间间隔,有效值为0-1440,单位是分钟。当间隔为0,测点不能带聚合逻辑;当间隔值大于0,测点必须带聚合逻辑。
startTime Query 必需 String 采样数据开始时间,支持local时间和UTC时间。local时间的格式为 YYYY-MM-DD HH:MM:SS。当格式为local时间时,使用设备所在地的当地时间进行查询。UTC时间格式需要加入时区信息,例如:2019-06-01T00:00:00+08:00。当格式为UTC时间时,对所有资产按照统一的开始时间和结束时间进行查询。
endTime Query 必需 String 采样数据结束时间,格式必须与开始时间保持一致。
pageSize Query 可选 Integer 单次查询返回记录条数的上限,默认为1000。
accessKey Query 可选 String 应用的服务账号,应用以accessKey进行鉴权以获得其被授权访问的数据。如何获取accessKey信息>>
localTimeAccuracy Query 可选 Boolean 指定查询结果是否包含毫秒级结果。true 表示需要毫秒格式,false 表示不需要毫秒格式。

响应参数

名称 数据类型 描述
data List<JSONObject> 资产数据列表。单设备单点的返回数据按时间升序排列。详见 items

items

示例
{
       "assetId": "yourAssetId",
       "timestamp": 1560249300000,
       "sum(yourPointId)": 4.246,
       "localtime": "2019-06-11 18:35:00"

}
参数
名称 数据类型 描述
assetId String 资产ID。
timestamp Long 数据时间戳,UNIX时间,精确到秒。
pointId Double 此参数是变量,在返回数据中显示为传入测点的标识符与查询到的测点数据。此处数据是电量PI的sum当天聚合。
localtime String 数据本地时间标记,精确到秒,当入参时间格式为UTC格式时,该值为null。

错误码

有关错误码的描述,参见 通用错误码

示例 1

请求示例

Local时间格式:

url: https://{apigw-address}/tsdb-service/v2.0/electric-power?orgId=yourOrgId&modelId=&assetIds=yourAssetIds&measurepointsWithLogic=sum(yourPointId)&interval=2&startTime=2019-06-01%2000:00:00&endTime=2019-06-11%2023:00:00&pageSize=&accessKey=accessKeyOfYourAPP

method: GET

返回示例

{
  "status": 0,
  "requestId": null,
  "msg": "success",
  "submsg": null,
  "data": {
    "items": [
      {
        "assetId": "yourAssetId",
        "timestamp": 1560249300000,
        "sum(yourPointId)": 6.853,
        "localtime": "2019-06-11 18:35:00"
      },
      {
        "assetId": "yourAssetId",
        "timestamp": 1560249420000,
        "sum(yourPointId)": 4.246,
        "localtime": "2019-06-11 18:37:00"
      }
    ]
  }
}

示例 2

请求示例

UTC时间格式:

url: https://{apigw-address}/tsdb-service/v2.0/electric-power?orgId=yourOrgId&modelId=&assetIds=yourAssetIds&measurepointsWithLogic=sum(yourPointId)&interval=2&startTime=2019-06-01T10:00:00%2B08:00&endTime=2019-06-11T23:00:00%2B08:00&pageSize=&accessKey=accessKeyOfYourAPP

method: GET

返回示例

{
    "status": 0,
    "requestId": null,
    "msg": "success",
    "submsg": null,
    "data": {
        "items": [
            {
                "localtime": null,
                "sum(yourPointId)": 6.853,
                "assetId": "yourAssetId",
                "timestamp": 1560249300000
            },
            {
                "localtime": null,
                "sum(yourPointId)": 4.246,
                "assetId": "yourAssetId",
                "timestamp": 1560249420000
            }
        ]
    }
}

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 GetMethod {

    private static class Request extends PoseidonRequest {

        public void setQueryParam(String key, Object value){
            queryEncodeParams().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
        String accessKey = "AccessKey of your APP";
        String secretKey = "SecretKey of your APP";

        //新建一个request 然后把需要的参数传进去存在query的map中,key是参数名字,value是参数值
        Request request = new Request();
        request.setQueryParam("orgId", "yourOrgId");
        request.setQueryParam("modelId", "yourModelId");
        request.setQueryParam("assetIds","yourAssetIds");
        request.setQueryParam("measurepointsWithLogic", "sum(yourPointId)");
        request.setQueryParam("interval", 10);
        request.setQueryParam("startTime", "2019-06-01 00:00:00"); //或UTC时间:2019-06-01T00:00:00+08:00
        request.setQueryParam("endTime", "2019-06-11 23:00:00");   //或UTC时间:2019-06-11T23:00:00+08:00
        request.setQueryParam("pageSize" , 10);

        request.setMethod("GET");

        try {
            JSONObject response =  Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                    .url("https://{apigw-address}/tsdb-service/v2.0/electric-power")
                    .getResponse(request, JSONObject.class);
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

使用POST方法

请求格式

POST https://{apigw-address}/tsdb-service/v2.0/electric-power

请求参数(Body)

名称 必需/可选 数据类型 描述
orgId 必需 String 资产所属的组织ID。如何获取orgId信息>>
modelId 可选 String 资产所属模型ID。如何获取modelId信息>>
assetIds 必需 String 资产ID,支持查询多个资产,多个资产ID之间用英文逗号隔开。如何获取Asset ID信息>>
measurepointsWithLogic 必需 String 测点数据聚合逻辑,支持的聚合计算方式有count, avg, sum, max, min, first, last。聚合查询的时间区间为 [startTime,endTime),即聚合操作数包含 startTime 时刻的数据,但不包含 endTime 时刻的数据。格式为:函数(测点标识符),支持查询多个测点,例如:sum(pointId1),sum(pointId2)如何获取pointId信息>>
interval 必需 String 聚合算法作用的时间间隔,有效值为0-1440,单位是分钟。当间隔为0,测点不能带聚合逻辑;当间隔值大于0,测点必须带聚合逻辑。
startTime 必需 String 采样数据开始时间,支持local时间和UTC时间。local时间的格式为 YYYY-MM-DD HH:MM:SS。当格式为local时间时,使用设备所在地的当地时间进行查询。UTC时间格式需要加入时区信息,例如:2019-06-01T00:00:00+08:00。当格式为UTC时间时,对所有资产按照统一的开始时间和结束时间进行查询。
endTime 必需 String 采样数据结束时间,格式必须与开始时间保持一致。
pageSize 可选 String 单次查询返回记录条数的上限,默认为1000。
accessKey 可选 String 应用的服务账号,应用以accessKey进行鉴权以获得其被授权访问的数据。如何获取accessKey信息>>
localTimeAccuracy 可选 String 指定查询结果是否包含毫秒级结果。true 表示需要毫秒格式,false 表示不需要毫秒格式。

响应参数

参见 使用GET方法 中的描述。

错误码

有关错误码的描述,参见 通用错误码

示例 1

请求示例

Local时间格式:

url: https://{apigw-address}/tsdb-service/v2.0/electric-power

method: POST

Content-Type: multipart/form-data;charset=UTF-8

requestBody:
{
  "orgId": "yourOrgId",
  "assetIds": "yourAssetIds",
  "measurepointsWithLogic": "sum(yourPointId)",
  "startTime": "2020-03-01 00:00:00",
  "endTime": "2020-03-01 00:15:00",
  "accessKey": "accessKey of your APP"
}

返回示例

{
  "status": 0,
  "requestId": null,
  "msg": "success",
  "submsg": null,
  "data": {
    "items": [
      {
        "assetId": "yourAssetId",
        "timestamp": 1560249300000,
        "sum(yourPointId)": 6.853,
        "localtime": "2019-06-11 18:35:00"
      },
      {
        "assetId": "yourAssetId",
        "timestamp": 1560249420000,
        "sum(yourPointId)": 4.246,
        "localtime": "2019-06-11 18:37:00"
      }
    ]
  }
}

示例 2

请求示例

UTC时间格式:

url: https://{apigw-address}/tsdb-service/v2.0/electric-power

method: POST

Content-Type: multipart/form-data;charset=UTF-8

requestBody:
{
  "orgId": "yourOrgId",
  "assetIds": "yourAssetIds",
  "measurepointsWithLogic": "sum(yourPointId)",
  "startTime": "2019-06-01T10:00:00%2B08:00",
  "endTime": "2019-06-11T23:00:00%2B08:00",
  "pageSize": 1000,
  "accessKey": "accessKey of your APP"
}

返回示例

{
    "status": 0,
    "requestId": null,
    "msg": "success",
    "submsg": null,
    "data": {
        "items": [
            {
                "localtime": null,
                "sum(yourPointId)": 6.853,
                "assetId": "yourAssetId",
                "timestamp": 1560249300000
            },
            {
                "localtime": null,
                "sum(yourPointId)": 4.246,
                "assetId": "yourAssetId",
                "timestamp": 1560249420000
            }
        ]
    }
}

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 PostMethod {

    private static class Request extends PoseidonRequest {

        public void setFormParam(String key, String value){
            formParams().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
        String accessKey = "AccessKey of your APP";
        String secretKey = "SecretKey of your APP";

        //新建一个request 然后把需要的参数传进去存在form的map中,key是参数名字,value是参数值
        Request request = new Request();
        request.setFormParam("orgId", "yourOrgId");
        request.setFormParam("modelId", "yourModelId");
        request.setFormParam("assetIds","yourAssetIds");
        request.setFormParam("measurepointsWithLogic", "sum(yourPointId)");
        request.setFormParam("interval", "10");
        request.setFormParam("startTime", "2019-06-01 00:00:00"); //或UTC时间:2019-06-01T00:00:00+08:00
        request.setFormParam("endTime", "2019-06-11 23:00:00");   //或UTC时间:2019-06-11T23:00:00+08:00
        request.setFormParam("pageSize", "10");

        request.setMethod("POST");

        try {
            JSONObject response =  Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
                    .url("https://{apigw-address}/tsdb-service/v2.0/electric-power")
                    .getResponse(request, JSONObject.class);
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}