数据中心
数据中心用来保存 RHILEX 采集到的的数据。
属性查看
在左侧树形列表即可查看数据中心的表字段属性。
数据写入
数据写入数据中心需要用 Lua 脚本来支持,具体的函数:
Lua
local error = rds:Save('uuid', dataKVTable)
下面是一个案例:将读取到的水质数据写入数据中心:
Actions = {
function(args)
local dataT, err = json:J2T(args);
if err ~= nil then
Throw(err);
return true, args;
end;
local schemaData = {};
for _, row in ipairs(dataT) do
schemaData[row.tag] = row.value;
end;
local err = rds:Save("SCHEMAZ848ZRDG", {
temp = (schemaData.t1 + schemaData.t2 + schemaData.t3) / 3,
resistivity = schemaData.resistivity,
conductivity = schemaData.conductivity,
dissolved_oxygen = schemaData.dissolved_oxygen,
ph_value = schemaData.ph_value
});
if err ~= nil then
Throw(err);
return 0;
end;
return true, args;
end
};
数据读取
RHILEX 数据中心提供了 HTTP 接口来获取存储的数据,需要注意的是 HTTP 接口需要一个 token,其配置在 rhilex.ini 中:
rhilex.ini
; Dataschema API secret
dataschema_secrets = rhilex-secret
RHILEX 提供了快速请求构建功能,点击【快速请求】即可获取请求的 URL:
历史数据
下面是获取历史数据的 CURL 示例:
curl --location --request GET `'http://127.0.0.1:2580/api/v1/datacenter/queryDataList?secrets=secrets&uuid=<uuid>¤t=<current>&size=<size>&order=<order>&select=<select>'` \
--header 'User-Agent: RHILEX'
参数
uuid
:数据中心的 IDsecrets
:请求秘钥current
:当前页size
:每页数据,最多 1000 条select
:选择的字段,形式为:filed1,filed2,....
,用,
隔开,原理和 SQL 的select
字段一样。 查询示例:
JSON
{
"code": 200,
"msg": "Success",
"data": {
"current": 1,
"size": 2,
"total": 30,
"records": [
{
"create_at": "2024-05-11T13:16:07Z",
"id": 21,
"oxygen": 20.78,
"ph_value": 7.5,
"temperature": 25.44,
"warning": "运行信息"
},
{
"create_at": "2024-05-11T13:16:07Z",
"id": 22,
"oxygen": 20.78,
"ph_value": 7.5,
"temperature": 25.44,
"warning": "运行信息"
}
]
}
}
最新数据
下面是获取最新数据的 CURL 示例:
curl --location --request GET 'http://127.0.0.1:2580/api/v1/datacenter/queryLastData?secrets=secrets&uuid=<uuid>&select=<select>' \
--header 'User-Agent: RHILEX'
参数
uuid
:数据中心的 IDsecrets
:请求秘钥select
:选择的字段,形式为:filed1,filed2,....
,用,
隔开,原理和 SQL 的select
字段一样。
查询示例:
JSON
{
"code": 200,
"msg": "Success",
"data": {
"create_at": "2024-05-10 18:56:45",
"id": 81,
"oxygen": 20.78,
"ph_value": 7.5,
"temperature": 25.44,
"warning": "运行信息"
}
}
💡
secrets 是外部应用请求秘钥,在 rhilex.ini
配置文件中配置,如果有特殊符号记得编码 URL。
导出数据
点击【导出】按钮即可导出当前存储的数据。
清空数据
点击【清空】按钮即可清空所有数据。
⚠️
该操作会直接物理删除所有的数据,请做好备份再清空。