Flux query syntax help

Hi,

I use graphana to querry some influxDb value.

I have temperature, Humidity, timestamp, ID and EUI

If I make a querry without EUI or ID, all work well

On my querry I would like to have only the value with ID 1

I make this querry and it return 0 row

from(bucket: "borealis")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "borealis")
  |> filter(fn: (r) => r["_field"] == "TEMPERATURE")
  |> filter(fn: (r) => r["_field"] == "ID" == 1)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Same question about the EUI line. The exception is it,s a string instead of a int

from(bucket: "borealis")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "borealis")
  |> filter(fn: (r) => r["_field"] == "TEMPERATURE")
  |> filter(fn: (r) => r["_field"] == "EUI" == 2CF7F1C052400221)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Can you show table view of your data when you query it without filter by ID?

Did you try something like this:

  |> filter(fn: (r) => r["ID"] == 1)
  |> filter(fn: (r) => r["EUI"] == "2CF7F1C052400221")

I have difficulty to figure how it really work.

I useNode-Red to store a value in Influx. The payload I send is something like this

When I check the influx database, both data seem to be in different line

What I want is a querry only showing the temperature if ID of the sensor is 1

Ok I achieve it By changinf the field name directly by TEMPERATURE1 TEMPERATURE2

You should use ID and EUI as tags, not as fields if they are used to identify unique metric.

In Node-RED you can prepare your payload like this:

msg.payload = [
    {
        measurement: "borealis",
        fields: {
            TEMPERATURE: 3.94
        },
        tags: {
            ID: 1,
            EUI: "2CF7F1C0435003CF",
        },
    },
    {
        measurement: "borealis",
        fields: {
            TEMPERATURE: 5.48
        },
        tags: {
            ID: 2,
            EUI: "2CF7F1C052400221",
        },
        timestamp: new Date()
    },      
];
return msg;

And then use influx batch node from node-red-contrib-influxdb so as to save data into InfluxDB.

Then you can easily filter by ID:

Or by EUI:

Corresponding Flux queries would be:

from(bucket: "DATA")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "borealis")
  |> filter(fn: (r) => r["_field"] == "TEMPERATURE")
  |> filter(fn: (r) => r["ID"] == "1")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")
from(bucket: "DATA")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "borealis")
  |> filter(fn: (r) => r["_field"] == "TEMPERATURE")
  |> filter(fn: (r) => r["EUI"] == "2CF7F1C0435003CF")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")
1 Like