0

I'm using InfluxDB and telegraf to have a dashboard.

InfluxDB v2.4.0 (git: de247bab08) build_date: 2022-08-18T19:41:15Z
Telegraf 1.23.4 (git: HEAD 5b48f5da)

My goal is to create a table with "firmware_version" for each "MCU".

telegraf input is an mqtt_consumer with this config

[[inputs.mqtt_consumer]]
  ....

  topics = [ "+/+/hal" ]

  name_override = "test"
  data_format = "json_v2"

  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "mcu"
      included_keys = ["target", "version"]
      disable_prepend_keys = true

The input (MQTT payload) looks like this

{
  "mcu": [
    {
      "target": "MCU_1",
      "version": "2022.08.1"
    },
    {
      "target": "MCU_2",
      "version": "2022.08.2"
    }
  ]
}

In addition to this mqtt_consumer, I have a processor regex to parse the topic and get the "cliend_id" and "device_id" where topic = <cliend_id>/<device_id>/hal The desired output is a table in "Web Admin Interface" of InfluxDB where I can see the version per MCU per device per client

Client Device Target Version
Client_1 Device_1 MCU_1 2022.08.1
Client_1 Device_1 MCU_2 2022.08.2
Client_2 Device_2 MCU_1 2022.07.1
Client_2 Device_2 MCU_2 2022.07.2

With my humble understand to the query syntax, I thought about this query

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "test")
  |> filter(fn: (r) => r["_field"] == "version")
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> last()

0 Answers0