项目案例
数据推送到 RDS

数据推送 RDS

RDS 是 RHILEX 自己的数据存储引擎, RHILEX 支持将采集到的数据保存到数据中心,为数据持久化服务。

实例

新建数据模型

rds

新建属性

rds

发布模型

rds

编写脚本

存储数据:rds:Save

Lua
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;
 

其中 UUID 参数是一开始建立的数据模型 ID,可以在快捷选择模板里面创建。

更新数据: rds:UpdateLast

Lua
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:UpdateLast("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;
 

其中 UUID 参数是一开始建立的数据模型 ID,可以在快捷选择模板里面创建。

⚠️

rds:UpdateLast 用来更新最后一条记录,如果没有数据则新建一个,如果有数据则永远是更新最后一条。

查看数据

rds

外部接口

数据中心提供了外部接口供给外部应用使用。比如组态编辑器 FUXA 等。

历史数据

下面是 CURL 示例:

curl --location --request GET 'http://127.0.0.1:2580/api/v1/datacenter/queryDataList?uuid=<uuid>&current=<current>&size=<size>&order=<order>&select=<select>' \
--header 'User-Agent: RHILEX'

参数说明:

  • uuid:数据中心的 ID
  • 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?uuid=<uuid>&select=<select>' \
--header 'User-Agent: RHILEX'
  • uuid:数据中心的 ID
  • 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": "运行信息"
  }
}
© 2023-2025 RHILEX Technologies Inc. All rights reserved.