Retrieve influxdb with Nodered

I'm trying to retrieve the most recent 2 items from InfluxDB via Nodered for further processing. I can't seem to combine the items and get the last values.
This works:
SELECT last(Temperature) FROM environment where Location = '5th_wheel'
but it only returns one value.

This works but gets the oldest readings:
select "Temperature", "Humidity" FROM environment WHERE Location = '5th_wheel' LIMIT 1

This draws an error:
select last("Temperature", "Humidity") FROM environment WHERE Location = '5th_wheel'
"Error: Error from InfluxDB: invalid number of arguments for last, expected 1, got 2"

Not sure if this worked because the timecode is wrong:
select last("Temperature"), last("Humidity") FROM environment WHERE Location = '5th_wheel'

0: object
time: "1970-01-01T00:00:00.000Z"
last: 39
last_1: 66.2

Any idea of what the right query would be??

order by time desc limit 2
Or something like that. Check the docs if it isn't quite right.

Thanks that got me on the right track.
select "Temperature", "Humidity" FROM environment WHERE Location = '5th_wheel' order by time desc limit 1

You said you wanted two.

2 values, temperature and humidity, but the most recent

Now that I have the query working in Nodered for my influxDB data, I need to build the http request part of it. I can't find the right example online. I want to use http://192.168.0.25:1880/basement to retrieve the most recent basement temperature and humidity reading from the influxDB and return those readings in a JSON string. Once I have this working I can change up the basement for another location that will be used as part of the query. (FYI, the data in the influxDB is updated once a minute via MQTT nodes in various locations.)

Any ideas on how to manage this?

Start by looking at the http examples in the node red cookbook.

Then best to start a new thread if necessary with an appropriate subject line.

found an example

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.