# Displaying data in node red dashboard by using the last collected data in InfluxDB

**URL:** https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134
**Category:** Dashboard
**Tags:** node-red-dashboard, database, mqtt
**Created:** [30 December 2023 15:17 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134 "2023-12-30T15:17:52Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![OlsenOw](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@OlsenOw](https://discourse.nodered.org/u/OlsenOw)
#### Post date: [30 December 2023 15:17 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/1 "2023-12-30T15:17:52Z")

</div>

Hello everyone,

I'm fairly new to node-red and I might need suggestions on how can I do it, much appreciated !

As the title says, I'm trying to display the last collected data from InfluxDB that indicates the active/inactive status from my pir motion sensor, but i'm lost at how can i get the data from influxdb, i tried using the influxCLI to query `select * from motion order by time desc limit 1` and it returns exactly what i want as it shows the newest collected data from influxdb. The problem is how i should get the data from node red?

Any kindhearted soul can provide me some guidance?

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [30 December 2023 15:32 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/2 "2023-12-30T15:32:13Z")

</div>

Welcome to the forum:

> **[node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb)**
>
> Node-RED nodes to save and query data from an influxdb time series database

> **[first() function | Flux Documentation](https://docs.influxdata.com/flux/v0/stdlib/universe/first/)**
>
> first() returns the first non-null record from each input table.

---

<div class="post-metadata">

### Author: ![OlsenOw](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@OlsenOw](https://discourse.nodered.org/u/OlsenOw)
#### Post date: [30 December 2023 17:04 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/3 "2023-12-30T17:04:59Z")

</div>

i mean which node is the best? i also have the influxdb palette installed, i looked at inject node and status node but it doesn't display the last collected data, also the first() is the oldest data, what i need is the newest data

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 December 2023 17:16 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/4 "2023-12-30T17:16:51Z")

</div>

> [@OlsenOw](#):
>
> first() is the oldest data, what i need is the newest data

Did you look at the docs? Not surprisingly it is `last` that you need.  
You can use an Inject node to feed the query into the influx node.

---

<div class="post-metadata">

### Author: ![OlsenOw](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@OlsenOw](https://discourse.nodered.org/u/OlsenOw)
#### Post date: [30 December 2023 17:27 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/5 "2023-12-30T17:27:04Z")

</div>

yeah i saw that just now, currently studying it how it works

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 December 2023 17:31 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/6 "2023-12-30T17:31:07Z")

</div>

Are you using influxdb 1.x or 2.x?

---

<div class="post-metadata">

### Author: ![OlsenOw](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@OlsenOw](https://discourse.nodered.org/u/OlsenOw)
#### Post date: [30 December 2023 17:33 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/7 "2023-12-30T17:33:22Z")

</div>

i'm using influx 1.6.5

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 December 2023 17:43 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/8 "2023-12-30T17:43:37Z")

</div>

Wow, that is ancient. The query language for 1.8 and below is not flux, you will have to find the docs for the earlier query language for that version. It will look much more like conventional SQL.

---

<div class="post-metadata">

### Author: ![OlsenOw](https://avatars.discourse-cdn.com/v4/letter/o/dfb087/32.png) [@OlsenOw](https://discourse.nodered.org/u/OlsenOw)
#### Post date: [30 December 2023 18:09 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/9 "2023-12-30T18:09:56Z")

</div>

yeah because im using raspberry pi 4 and the intended installation of influxdb cloud is not working for me and im not going to dig my head into that for days without progressing anything. So i just use my university prof's influxdb version for ease, plus he taught me with that version and im just going stick with that without those error logs bugging me

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [29 January 2024 18:10 UTC](https://discourse.nodered.org/t/displaying-data-in-node-red-dashboard-by-using-the-last-collected-data-in-influxdb/84134/10 "2024-01-29T18:10:34Z")

</div>

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