Appearance
设备数据
设备数据提供了获取设备实时数据的功能,可以用于监控设备状态和数据采集。
获取设备数据
http
GET /api/v2/devices/{device_id}/data/接口说明
获取设备的实时数据,包括各个因子的当前值和时间戳。
响应
返回数据 (200 OK)
json
{
"success": true,
"data": [
{
"agri_id": "因子ID",
"value": 23.5,
"t": 0
},
{
"agri_id": "因子ID",
"value": 45.2,
"t": 0
}
],
"error": null
}响应参数
| 字段 | 类型 | 说明 |
|---|---|---|
agri_id | string | 因子的完整ID |
value | number | 数据值 |
t | integer | 数据时间戳(UTC时间) |
代码示例
Python
python
def get_device_data(device_id):
"""获取设备实时数据
Args:
device_id: 设备ID
"""
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}"
}
url = f"{API_BASE}/devices/{device_id}/data/"
response = requests.get(url, headers=headers)
return response.json()
# 使用示例
device_id = "device_123456"
result = get_device_data(device_id)
if result['success']:
for data_point in result['data']:
print(f"因子: {data_point['agri_id']}, 值: {data_point['value']}")cURL
bash
curl -X GET "https://ums.holdingbyte.com/api/v2/devices/device_123456/data/" \
-H "Authorization: Bearer your_access_token"错误响应
错误响应
设备数据API可能返回的错误响应遵循统一的格式。有关详细的错误码和处理方法,请参阅API错误响应文档。
常见错误
| 错误码 | 说明 |
|---|---|
| 401 | 未认证 |
| 403 | 无权限 |
| 404 | 设备不存在 |
| 400 | 请求参数错误 |
