IoT数据获取

注意事项

调用该接口使用Bearer token,Bearer token的含义是在请求的header中添加Authorization参数并且值是Bearer {access_token},注意Bearer和access_token之间有空格。

1、获取上云数据

1、请确保您已在IoT平台上申请了租户,并在IoT添加了产品;
2、请以租户管理员或开发者的邮箱来申请该接口的权限,邮件地址详见平台首页底部“联系我们”,邮件回复将提供token生成依赖的appId和appSecret;
3、此接口查询数据结束时间和开始时间之间不能超过3分钟;
1.1 接口名
https://open.apps.paas.se-unicloud.com/iot-open-push/device/getData
1.2 调用方式
调用方式使用POST,application/json方式
1.3 请求参数
参数名 类型 是否必填 含义 示例
subDomainId string 在iot平台上添加产品的id 123
beginTime string 查询数据的开始时间戳(毫秒) 1618310401000
endTime string 查询数据的结束时间戳(毫秒) 1618310463508
compress bool 是否需要压缩(true:返回的data数据将是gzip压缩后的数据,压缩算法请查看1.6) false
json示例
{
    "subDomainId":"123",
    "beginTime": 1618310401000,
    "endTime": 1618310463508,
    "compress": false

}
1.4 返回参数
参数名 类型 含义 示例
id string 记录编号 607574742c4a22001b8959a0
physicalDeviceId string 网关设备id SQLtest001
domainId string iot平台租户id 123
subDomainId string iot平台产品id 1
message string 具体的采集数据 {}
logTime string 数据存储的时间 2021-04-13T10:41:03.000+0000
msgType string 数据上报类型 事件上报
1.5 返回示例
{
    "code": 1,
    "message": "success",
    "data": [
        {
            "id": "607574742c4a22001b8959a0",
            "physicalDeviceId": "SQLtest001",
            "domainId": "123",
            "subDomainId": "1",
            "message": "{\"id\":null,\"ct\":1618310463000,\"tp\":\"vitualTest_e\",\"d\":[{\"ct\":1618310462191,\"v\":\"1\",\"tag\":\"E0021DJMH0|G01|ES-G-0004\"}]}",
            "msgType": "事件上报",
            "logTime": "2021-04-13T10:41:03.000+0000"
        }
}
1.6 gzip压缩和解压
  /**
     * 使用gzip进行压缩
     */
    public static String compress(String primStr) {
        if (primStr == null || primStr.length() == 0) {
            return primStr;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = null;
        try {
            gzip = new GZIPOutputStream(out);
            gzip.write(primStr.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (gzip != null) {
                try {
                    gzip.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return new sun.misc.BASE64Encoder().encode(out.toByteArray());
    }

    /**
     * 使用gzip进行解压缩
     */
    public static String uncompress(String compressedStr) {
        if (compressedStr == null) {
            return null;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream in = null;
        GZIPInputStream ginzip = null;
        byte[] compressed = null;
        String decompressed = null;
        try {
            compressed = new sun.misc.BASE64Decoder().decodeBuffer(compressedStr);
            in = new ByteArrayInputStream(compressed);
            ginzip = new GZIPInputStream(in);

            byte[] buffer = new byte[1024];
            int offset = -1;
            while ((offset = ginzip.read(buffer)) != -1) {
                out.write(buffer, 0, offset);
            }
            decompressed = out.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ginzip != null) {
                try {
                    ginzip.close();
                } catch (IOException e) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            try {
                out.close();
            } catch (IOException e) {
            }
        }
        return decompressed;
    }

results matching ""

    No results matching ""