# Node-Red to Influxdb Batch Node

**URL:** <https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288>\
**Category:** General\
**Created:** [13 August 2019 16:45 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288 "2019-08-13T16:45:24Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [13 August 2019 16:45 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/1 "2019-08-13T16:45:24Z")

</div>

Hi All,  
I am in the process of converting flow data from a wetland monitoring site that I want to display in Grafana from an Infludb database. The data is received daily in the form of an excel sheet from the provider which I isolate and parse through a number of nodes. I believe I am almost there but am stumped at the final hurdle. The 'measurements' are coming through to Grafana but the data points are absent. The debug output from one of the measurements (there are 5) looks like this:  
{"measurement":"site1dailyvol","fields":{"sp1dailyvol":25.18999863},"tags":{"location":"sp1"},"timestamp":1564293600000}, .................

Anyone have suggestions that would enable the data points to display?

---

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [13 August 2019 16:54 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/2 "2019-08-13T16:54:44Z")

</div>

Also the function code to set the variables looks like this:  
var site1 = msg.payload[0].rank;  
var dailyvol1 = parseFloat(msg.payload[0].value);  
var timestamp1 = Date.parse(msg.payload[0].date);

And the msg.payload:  
msg.payload =  
[  
{  
measurement: "site1dailyvol",  
fields: {  
sp1dailyvol: dailyvol1  
},  
tags:{  
location:"sp1"  
},  
timestamp: timestamp1  
},

---

<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:** [13 August 2019 18:39 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/3 "2019-08-13T18:39:23Z")

</div>

Have you tried running the influxdb command line client to check the points are getting into the db ok?

---

<div class="post-metadata">

**Author:** ![igrowing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/igrowing/32/663_2.png) [@igrowing](https://discourse.nodered.org/u/igrowing)\
**Post date:** [14 August 2019 12:41 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/4 "2019-08-14T12:41:57Z")

</div>

Hi @jasjnr  
Before getting charts in Grafana, make sure you have data in IndluxDB.  
Do you see the data in your measurement?

```auto
influx
use <your_DB>
select * from <your_measurement> limit 10

```

If none, then the problem is is posting data to the DB.

---

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [14 August 2019 14:47 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/5 "2019-08-14T14:47:13Z")

</div>

It does appear the data is being entered:

> select \* from site1dailyvol limit 10  
> name: site1dailyvol  
> time location sp1dailyvol

* * *

1556690400000 sp1 60.43000031  
1556776800000 sp1 29.67000008  
1556863200000 sp1 26.94999886  
1556949600000 sp1 28.86999893  
1557036000000 sp1 29.01000023  
1557122400000 sp1 31.84999847  
1557208800000 sp1 28.70999908  
1557295200000 sp1 47.66999817  
1557381600000 sp1 45.43000031  
1557468000000 sp1 25.84000015

---

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [14 August 2019 15:00 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/6 "2019-08-14T15:00:00Z")

</div>

![Grafana](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/faba29e10e776ff10f9d931c291f411950edaea1.jpeg)

---

<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:** [14 August 2019 15:03 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/7 "2019-08-14T15:03:10Z")

</div>

Your timestamps have not got nearly enough zeros on them, mine look like  
1558383607687159973  
though I must say I am surprised to see so many on mine

---

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [14 August 2019 15:08 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/8 "2019-08-14T15:08:09Z")

</div>

Thanks Colin. In the function node prior to the Influxdb Batch node I use the following to convert the date record to unix time:  
var timestamp1 = Date.parse(msg.payload[0].date);

---

<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:** [14 August 2019 15:15 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/9 "2019-08-14T15:15:39Z")

</div>

Yes I saw that, and it looks correct. I haven't used the batch node just the basic one, but I do remember at least one other post where the timestamps did not seem to be going in correctly using the batch node.  
The link below does say they should be in nanoseconds, which I think agrees with the numbers I have. Try multiplying by 10^6 and see what happens. Something like  
`var timestamp1 = Date.parse(msg.payload[0].date).getTime()*1000000`

> **[What time formats are allowed?](https://support.influxdb.com/hc/en-us/articles/205177928-What-time-formats-are-allowed-)**
>
> Writes using the line protocol accept the following time formats:
> 
> Unix nanosecond timestamp which, per Wikipedia, is elapsed nanoseconds since 00:00:00 Coordinated Universal Time (UTC), Thursday...

---

<div class="post-metadata">

**Author:** ![jasjnr](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jasjnr](https://discourse.nodered.org/u/jasjnr)\
**Post date:** [14 August 2019 15:27 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/10 "2019-08-14T15:27:07Z")

</div>

Well spotted Colin!  
I updated the code with another variable to then multiply and it worked a treat:

var timeParse1 = Date.parse(msg.payload[0].date);  
var timestamp1 = timeParse1\*1000000;

Thanks for your help!

---

<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:** [14 August 2019 15:28 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/11 "2019-08-14T15:28:34Z")

</div>

It would be worth putting an issue on the node's github page pointing out that the readme needs clarification of what the timestamp should be.

---

<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 August 2019 16:12 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/12 "2019-08-15T16:12:50Z")

</div>

I have submitted an issue

> <https://github.com/mblackstock/node-red-contrib-influxdb/issues/44>

---

<div class="post-metadata">

**Author:** ![igrowing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/igrowing/32/663_2.png) [@igrowing](https://discourse.nodered.org/u/igrowing)\
**Post date:** [15 August 2019 16:57 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/13 "2019-08-15T16:57:03Z")

</div>

if you remove all "group by" arguments, the chart will appear as it is, without additional changes.

---

<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 August 2019 19:26 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/14 "2019-08-15T19:26:03Z")

</div>

Can you explain why? Given that it works as it is if the timestamp is passed in microseconds?

---

<div class="post-metadata">

**Author:** ![igrowing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/igrowing/32/663_2.png) [@igrowing](https://discourse.nodered.org/u/igrowing)\
**Post date:** [16 August 2019 06:54 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/15 "2019-08-16T06:54:15Z")

</div>

Given advice isn't a must. It's personal preference. The reason behind it: less code, less bugs.  
However, common thumb rule is good enough: if existing code works, don't touch it 🙂

---

<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 August 2019 07:41 UTC](https://discourse.nodered.org/t/node-red-to-influxdb-batch-node/14288/16 "2019-08-16T07:41:15Z")

</div>

I don't understand why removing the "group by" would have fixed the problem, which appeared to be to do with the way the data was being added to influx, not to do with the grafana.
