阿里云物联网获取设备属性api接口:QueryDevicePropertyData

news/2025/3/4 13:42:08/

阿里云物联网接口:QueryDevicePropertyData
 说明:调用该接口查询指定设备或数字孪生节点,在指定时间段内,单个属性的数据

比如提取上传到物联网的温度数据

api文档:QueryDevicePropertyData_物联网平台_API文档-阿里云OpenAPI开发者门户QueryDevicePropertyData调用该接口查询指定设备或数字孪生节点,在指定时间段内,单个属性的数据。是物联网平台的API文档,是阿里云OpenAPI开发者门户提供的OpenAPI开发手册,包括云产品的OpenAPI、出入参、错误码、变更历史。https://next.api.aliyun.com/document/Iot/2018-01-20/QueryDevicePropertyData


阿里云物联网平台云端SDK下载:

    物联网平台SDK下载地址和示例_物联网平台(IoT)-阿里云帮助中心物联网平台云端SDK支持Java、Python、PHP、Node.js、.NET、Go和Swift语言,用于调用云端API,以实现物联网平台的云端能力,如产品管理、设备管理、Topic管理、数据流转规则管理、消息通信等。本文介绍云端SDK的下载地址及使用示例。https://help.aliyun.com/zh/iot/developer-reference/download-iot-platform-sdks-2

    搞了好久才搞出来:

    • 1、java实现:

    • QueryDeviceTempData.java

    package com.example.iot;import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.iot.model.v20180120.QueryDevicePropertyDataRequest;
    import com.aliyuncs.iot.model.v20180120.QueryDevicePropertyDataResponse;
    import com.aliyuncs.profile.DefaultProfile;
    import com.aliyuncs.profile.IClientProfile;public class QueryDeviceTempData {public static void main(String[] args) {// 阿里云访问密钥String accessKeyId = "**";String accessKeySecret = "**";String regionId = "cn-shanghai";// 设备信息String productKey = "**";String deviceName = "**";// 初始化客户端IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);IAcsClient client = new DefaultAcsClient(profile);// 创建请求QueryDevicePropertyDataRequest request = new QueryDevicePropertyDataRequest();request.setProductKey(productKey);request.setDeviceName(deviceName);request.setIdentifier("indate"); // 温度属性标识符request.setStartTime(System.currentTimeMillis() - 3600 * 1000); // 查询过去一小时的数据request.setEndTime(System.currentTimeMillis());request.setAsc(1); // 按时间升序排列request.setPageSize(10); // 每页返回的数据条数try {// 发送请求并获取响应QueryDevicePropertyDataResponse response = client.getAcsResponse(request);System.out.println("Response: " + response);// 解析响应if (response != null && response.getData() != null) {for (QueryDevicePropertyDataResponse.Data.PropertyInfo propertyInfo : response.getData().getList()) {System.out.println("Time: " + propertyInfo.getTime() + ", Value: " + propertyInfo.getValue());}}} catch (ClientException e) {e.printStackTrace();}}
    }

    • pom.xml文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>QueryDevicePropertyData</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- 阿里云核心库 --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.3</version></dependency><!-- 阿里云物联网平台SDK --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-iot</artifactId><version>7.4.0</version></dependency></dependencies></project>
    • java项目结构
    • java输出:

    Response: com.aliyuncs.iot.model.v20180120.QueryDevicePropertyDataResponse@38d8f54a
    Time: 1740729954244, Value: 18.0
    Time: 1740730254422, Value: 18.0
    Time: 1740730554592, Value: 18.0
    Time: 1740730854785, Value: 18.0
    Time: 1740731154962, Value: 17.0
     

    2、python实现

    输出json格式,想要哪些字段自行解析

    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.acs_exception.exceptions import ClientException
    from aliyunsdkcore.acs_exception.exceptions import ServerException
    from aliyunsdkiot.request.v20180120.QueryDevicePropertyDataRequest import QueryDevicePropertyDataRequest# 设置你的AccessKey ID和AccessKey Secret
    access_key_id = '**'
    access_key_secret = '**'
    region_id = 'cn-shanghai'  # 根据你的实际情况选择region# 创建AcsClient实例
    client = AcsClient(access_key_id, access_key_secret, region_id)# 创建QueryDevicePropertyDataRequest实例
    request = QueryDevicePropertyDataRequest()
    request.set_accept_format('json')# 设置请求参数
    request.set_ProductKey('**')  # 产品Key
    request.set_DeviceName('**')  # 设备名称
    request.set_Identifier('temp')  # 属性标识符
    request.set_StartTime(1740346648574)  # 开始时间,Unix时间戳,单位毫秒
    request.set_EndTime(1740357451888)  # 结束时间,Unix时间戳,单位毫秒
    request.set_PageSize(10)  # 每页记录数
    request.set_Asc(0)  # 0表示降序,1表示升序try:# 发送请求并获取响应response = client.do_action_with_exception(request)print(response.decode('utf-8'))
    except ClientException as e:print(e.get_error_code())print(e.get_error_msg())
    except ServerException as e:print(e.get_error_code())print(e.get_error_msg())

    python程序输出:{"RequestId":"036BBE41-52E9-5C5F-9312-D561C0D82282","Data":{"NextValid":false,"NextTime":1740355512752,"List":{"PropertyInfo":[{"Value":"-2.0","Time":1740357315548},{"Value":"-2.0","Time":1740357015021},{"Value":"-2.0","Time":1740356714858},{"Value":"-5.0","Time":1740356414687},{"Value":"-5.0","Time":1740356113089},{"Value":"-5.0","Time":1740355812915},{"Value":"-5.0","Time":1740355512754}]}},"Code":"","Success":true}


    http://www.ppmy.cn/news/1576555.html

    相关文章

    飞书考勤Excel导入到自己系统

    此篇主要用于记录Excel一行中&#xff0c;单条数据的日期拿取&#xff0c;并判断上下班打卡情况。代码可能满足不了大部分需求&#xff0c;目前只够本公司用&#xff0c;如果需要&#xff0c;可以参考。 需要把飞书月度汇总的考勤表导入系统中可以参考下。 下图为需要获取的年…

    快速入门 Prompt Engineering 提示工程

    1. 提示词与提示工程 什么是 Prompt 提示词? 相信阅读过 OpenAI 官方文档的同学都会发现&#xff0c;在文档中是找不到 question、answer 这类描述的&#xff0c;我们能看到的是 prompt 和 completion &#xff0c;翻译过来就是提示和补全。也就是说&#xff0c;我们与大模型…

    element-push el-date-picker日期时间选择器,禁用可选中的时间 精确到分钟

    效果 本来用的是时间段&#xff0c;但是甲方说不好用&#xff0c;让换成这样的 六百六十六 <el-form-item label"考评时间" class"is-required"><div style"display: flex; gap: 10px;"><el-form-item label"" style&…

    刷题日记——部分二分算法题目分享

    前言 咱们紧跟上一期结合时间复杂度浅谈二分法的好处, 并分享部分二分题目(将持续更新题目,绝对值你一个收藏)-CSDN博客 笔者接着分享一些刷过的关于二分算法的题目. 第一题 1283. 使结果不超过阈值的最小除数 - 力扣&#xff08;LeetCode&#xff09; 这道题就是典型的二…

    探索区块链数据:使用Python实现区块链数据分析

    探索区块链数据&#xff1a;使用Python实现区块链数据分析 在区块链和Web 3.0时代&#xff0c;数据分析变得尤为重要。区块链技术的去中心化和透明性为数据分析提供了丰富的资源和机会。作为区块链与Web 3.0、Python领域的著名自媒体创作者&#xff0c;笔名Echo_Wish&#xff…

    解决redis lettuce连接池经常出现连接拒绝(Connection refused)问题

    一.软件环境 windows10、11系统、springboot2.x、redis 6 7 linux&#xff08;centos&#xff09;系统没有出现这问题&#xff0c;如果你是linux系统碰到的&#xff0c;本文也有一定大参考价值。 根本思路就是&#xff1a;tcp/ip连接的保活(keepalive)。 二.问题描述 在spr…

    react脚手架配置别名

    1.在webpack.config.js中搜索关键字alias,新增别名。 2.tsconfig.json配置说明&#xff0c;主要是消除ts引入别名的报错。 新增配置

    软考教材重点内容 信息安全工程师 第18章 网络安全测评技术与标准

    18.1.1 网络安全测评概念 网络安全测评是指参照一定的标准规范要求&#xff0c;通过一系列的技术和管理方法&#xff0c;获取评估对象的网络安全状况信息&#xff0c;对其给出相应的网络安全情况综合判定。网络安全测评对象通常包括信息系统的组成要素或信息系统自身。 18.2 网…