使用EMQX的规则引擎,将采集到的数据存入TDengine

来自一搜便知
跳到导航 跳到搜索

测试数据信息

数据库:t1

表结构:dianyadianliu(ts timestamp,float dianya,float dianliu)

Mqtt消息:{"node_name": "modbus_tcp_1", "group_name": "DianYaDianLiu", "timestamp": 1654152622667, "values": {"dianya": 5, "dianliu": 6}, "errors": {}}

Mqtt主题:neuron/test1/upload

规则引擎设置

  1. 规则SQL
    SELECT
      payload.values as payload 
    FROM
      "neuron/test1/upload"
    WHERE
      group_name = "DianYaDianLiu"
    
  2. 响应动作
    1. 请求头
      Authorization Basic cm9vdDp0YW9zZGF0YQ==
      
    2. Body
      INSERT INTO t1.dianyadianliu VALUES(now,${payload.dianya},${payload.dianliu})
      
  3. 关联资源
    1. 请求URL
      http://192.168.99.125:6041/rest/sql/t1
      

啰嗦一句

最最最核心的东西我已经写出来了,这是我摸索了两三天才搞定的东西,如果你也遇到类似的问题且看到了这篇文章,希望这篇文章能够让你少走弯路;请一定要特别注意“测试数据信息”。