# Run InfluxDB query and display in debug

**URL:** <https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681>\
**Category:** General\
**Created:** [15 March 2021 18:12 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681 "2021-03-15T18:12:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 18:12 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/1 "2021-03-15T18:12:39Z")

</div>

Hi. I need help from you guys who can help me. I'm not good in node red but I'm trying to.

I want to run a InfluxDB query syntax from node-red and display the result in debug. I noted that @Colin had been replied to similar process with mine at [Read data from InfluxDB](https://discourse.nodered.org/t/read-data-from-influxdb/21337) and from that @Colin suggested to see this post [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506).

The concept is I'm trying to view my single result in debug node red function like shown in the flow below:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a98832a6e800ab6dd773527e2e8f5435426072d2.png)

My query is about to read the last entry value from my measurements InfluxDB like:  
"SELECT volt1 FROM Voltage ORDER BY DESC LIMIT 1"

I don't know how to setup my InjectNode, Influxdb In Node and my DebugNode in a proper way. Is it possible I can get a single output result from debug console? Is there any complete tutorial how to do that?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 March 2021 18:15 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/2 "2021-03-15T18:15:29Z")

</div>

While not an "influxdb for node-red" tutorial, based on your questions, you really should spend a little time learning since many of the principles apply to all nodes.

So I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 19:01 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/3 "2021-03-15T19:01:46Z")

</div>

yup... i know about this but how to i want to read data from influxdb using node red debug node? the essential video didn't explain about the influxdb in at all..

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 March 2021 19:08 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/4 "2021-03-15T19:08:55Z")

</div>

No, it doesnt, but you asked...

> [@ayozzet](#):
>
> I don't know how to setup my InjectNode

> [@ayozzet](#):
>
> and my DebugNode in a proper way

these are very much covered.

* * *

Did you read the built in help...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98b35982b25bcf85cedb0ae7f5c630df99c069c9.png)

and the tip on the setup form?...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9028d9a2c05da295a546e48480831e5a592ae0f.png)

So set your inject to send the query in `msg.query`....  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92227076ae02df573a8bddbd50b9881ffc83dfca.png)

then the output (as the built in docs say) will come in `msg.payload`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96dc64121fdd6565fe3078455fa8a8563306107c.png)

So add a debug - it defaults to outputting `msg.payload`

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 19:49 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/5 "2021-03-15T19:49:34Z")

</div>

Sorry @Steve-Mcl for my rudeness in my last reply.  
I did try with your way but it seem like the output getting error like below.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4dcf3cef93f87409ec790cd1078c7cbb93625b9e.png)

and this is my setting for my influxdb  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc441bca85cf27a0cc7a3521133415bbec1955e2.png)

actually the setting for my database worked whenever i try to insert a data into influxdb.

Did I missed anything? It seem like your version of influxdb is different with mine. Could it be a problem with the version?

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 20:02 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/6 "2021-03-15T20:02:18Z")

</div>

... or do i need to create a function like below because in my database only appear timestamp (time) and the value (volt1):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/721505007e09bc86668d429b56162a58f05ade98.png)

---

<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:** [15 March 2021 20:16 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/7 "2021-03-15T20:16:40Z")

</div>

You have specified that you want to use flux as the query language, but the query you showed us influxql. Select the 1.x type in the influx node.

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 21:04 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/8 "2021-03-15T21:04:45Z")

</div>

wow... it's work!! thanks @Colin and @Steve-Mcl

so the Raw Output will be like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85baf2b6e021415b75690795bff5a2ac6e9fa198.png)

and the non-Raw Output will be like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d193e802c841538e246c212fcb227cd293e27e58.png)

Is there any post that can show me how to extract the value from the non-Raw Output? Because I'm thinking to get the value of "volt1" only... such as "402". After this I'm thinking to process the value and do some analysis.

---

<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:** [15 March 2021 21:23 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/9 "2021-03-15T21:23:12Z")

</div>

> [@ayozzet](#):
>
> Is there any post that can show me how to extract the value from the non-Raw Output?

You said you had watched the Essentials Guide videos, but I am sure there would be help with that question there. Also see this page from the docs. [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

I notice that your query appears to have returned a string for volt1. Does that mean that you are writing string values to database for something that is actually a number. If so then that is a bad idea. Make sure you provide it to influx as a Number not as a String. Unfortunately I think that means you will have to DROP the measurement and start again as it is not possible to change the field type once the field has been created.

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 21:32 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/10 "2021-03-15T21:32:16Z")

</div>

Yup I watched the videos so many times, and I make a lot of note about it. What I'm trying to say is I'm trying to extract the value using external Python Script for process it. Sorry for the incomplete question I asked just now. I hope you @Colin and @Steve-Mcl don't blame me.

---

<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:** [15 March 2021 21:40 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/11 "2021-03-15T21:40:25Z")

</div>

> [@ayozzet](#):
>
> trying to extract the value using external Python Script

Do you mean you want to extract the value from a message in node-red using a Python script to extract it? If so then that doesn't make any sense.

If you mean you want to extract the value in node red (which is described in the link I posted) and pass it to a python script then that is a different question. You can call a Python script using an Exec node and pass it whatever you like.

However, if that is what you mean, what are you doing in the script that cannot be done in node-red?

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 22:00 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/12 "2021-03-15T22:00:56Z")

</div>

Because I'm facing the node red consume my CPU usage (about 96%) when I try to process everything inside it... FYI, I have about 23 pcs of different sensors which are been located far from each other.... and each sensor having 3 topics to send through MQTT.... all raw data will be display in grafana.... As I just try just now, it seem like grafana also had a problem with streaming/refresh....

I'm still figuring it out how to solve the problem which is I don't know what it's going on when I deploy my extraction processes inside node red...

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [15 March 2021 22:06 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/13 "2021-03-15T22:06:12Z")

</div>

This is what happen if I try to run my extraction process inside node red

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6fe0ec8e2687d1d77900e0a37ff275acbb60016d.png)

---

<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:** [16 March 2021 07:28 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/14 "2021-03-16T07:28:22Z")

</div>

How often are the data arriving from each sensor? What hardware are you running on? Are you running node red, mosquito, influx and grafana all on the same computer? Where are you running the browser?

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [16 March 2021 11:32 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/15 "2021-03-16T11:32:06Z")

</div>

Each node need to send all the data every 100ms for 2 minutes. After the 2 minutes, the node will be in deep sleep mode for 58 minutes. I'm using TTGO T-Call board (ESP32+GSM SIM800L) and the sensors is ADS1115 (Sensing the voltage), soil pH sensor and DHT22 (but i'm using humidity value only).

And yes, I'm running mosquitto (as MQTT broker), node red (as client and as input via dashboard), influxdb (for database) and grafana (as graph display including data that I try to perform externally). I'm running everything on cloud server (Alibaba Elastic Server) with Ubuntu 20 installed. I'm running the browser remotely using chrome.

---

<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:** [16 March 2021 11:46 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/16 "2021-03-16T11:46:52Z")

</div>

> [@ayozzet](#):
>
> Each node need to send all the data every 100ms for 2 minutes

Can you explain what you mean by that? What is a node? How much data is it sending every 100ms?

Also what are you doing in the python code?

**[Edit]** Also, are all the nodes doing this at the same time or is it one after the other?

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [16 March 2021 12:08 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/17 "2021-03-16T12:08:19Z")

</div>

Node a.k.a the device which is the microcontroller with sensors. For each node, I'm not sure how much data been sending but what can I know is 3 data (voltage, ph value, humidity).

In python i'm trying to detect any kind of anomaly created. It just like graph pattern recognition. The value of voltage difference will be then plotted in grafana. I'm using influxdb data insertion for plotting.

Initially, I'm thinking to make the nodes send the data at the same time according to the time that has been sync with the gsm clock.

---

<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:** [16 March 2021 12:25 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/18 "2021-03-16T12:25:38Z")

</div>

Ok, in that case, you can run the python command from an exec node. Or you could run it separately from node red picking up the data directly from mqtt. Or you could run it from a Daemon node, numerous possibilities.

---

<div class="post-metadata">

**Author:** ![ayozzet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayozzet/32/38386_2.png) [@ayozzet](https://discourse.nodered.org/u/ayozzet)\
**Post date:** [16 March 2021 12:33 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/19 "2021-03-16T12:33:44Z")

</div>

WOW... you are really helpful @Colin. I didn't expect so much brilliant ideas I can get from around the world. But you are AWESOME!!!... Really appreciate it. I will try every suggestion you gave me. Thanks a lot.

---

<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:** [30 March 2021 12:34 UTC](https://discourse.nodered.org/t/run-influxdb-query-and-display-in-debug/42681/20 "2021-03-30T12:34:23Z")

</div>

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