I need to read a temperature present in an influx v1.8 database, using esp8266 and esp32 in Arduino. I am using the esp8266 influxdb library.
This query works from the command prompt on the influx server and also in Grafana:
SELECT last("temperature") FROM "sens848a6a6" WHERE time >= now() - 6h and time <= now()
The influxdb library does not like this: Query result error: {"error":"loc 1:13-1:26: string literal key \"temperature\" must have a value"}
I expect is only understant flux?
Using this as a query: String query = "from(bucket: \"test01/autogen\") |> range(start: -1m) |> filter(fn: (r) => r._measurement == \"sens848a6a6\" and r._field == \"temperature\")"; results in a 0 value.
This is the example code I used:
String query = "from(bucket: \"test01/autogen\") |> range(start: -1m) |> filter(fn: (r) => r._measurement == \"sens848a6a6\" and r._field == \"temperature\")";
// Send query to the server and get result
FluxQueryResult result = client.query(query);
while (result.next()) {
// Get typed value for flux result column 'temperature'
String temp = result.getValueByName("temperature").getString();
Serial.print("temperature: ");
Serial.print(temp);
// Get converted value for flux result column '_value' where there is RSSI value
long value = result.getValueByName("_value").getLong();
Serial.print(value);
Serial.println();
}
// Check if there was an error
if(result.getError() != "") {
Serial.print("Query result error: ");
Serial.println(result.getError());
}
So what is the correct way to get this sensor value from a V1.8 database?