# Reading from CSV file insert values into influx-DB

**URL:** <https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886>\
**Category:** General\
**Created:** [1 August 2022 15:15 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886 "2022-08-01T15:15:36Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [2 August 2022 12:27 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/22 "2022-08-02T12:27:39Z")

</div>

Finally i could able to successfully inject the data . thanks for the patience all my naïve questions

```auto
var newmsg2 = {};
newmsg2.payload = 
[
    [
        {
            PlcTime : msg.payload.PlcTime,
            CatalogNum : msg.payload.CatalogNum,
			SerialNum : msg.payload.SerialNum,
            FwVer : msg.payload.FwVer
        }
    ]
]
return newmsg2;

```

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

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [2 August 2022 12:30 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/23 "2022-08-02T12:30:04Z")

</div>

i have one more question , if this CSV file keeps on adding the row , how do i ensure only new data inject it

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 August 2022 12:40 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/24 "2022-08-02T12:40:53Z")

</div>

You would have to store the line number, or the last date field, then filter the output of the csv node. Or if the csv lines are created by node-red, add them to influx at that point.

---

<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:** [2 August 2022 12:50 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/25 "2022-08-02T12:50:38Z")

</div>

> [@Ferdi84](#):
>
> ` PlcTime : msg.payload.PlcTime`

Don't you want that as the time in the influx db? Also you said you wanted the serial number as a tag, as it is you have it as a field. I would have thought what you needed is

```auto
[
    {
        time: msg.payload.PlcTime,
        CatalogNum: msg.payload.CatalogNum,
        SerialNum: msg.payload.SerialNum,
        FwVer: msg.payload.FwVer
    },
    {
        SerialNum : msg.payload.SerialNum
    }
]

```

---

<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:** [2 August 2022 12:57 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/26 "2022-08-02T12:57:28Z")

</div>

As you currently have it the time field is the time you added the record to the db. If you make the plc time be the influx time as I suggested above, then it won't actually matter if you add the same record again, it will just overwrite the previous one with the new one.

However, I see that you have multiple records with the same time, which means that you can't do what I was suggesting.

Are you sure influx is the right database for this?

---

<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:** [2 August 2022 16:03 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/27 "2022-08-02T16:03:19Z")

</div>

> [@Ferdi84](#):
>
> how do i ensure only new data inject it

Can you not get the data in real time from the plc, rather than fetching a file? It would make it much simpler.

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [3 August 2022 03:18 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/28 "2022-08-03T03:18:18Z")

</div>

my final aim to plot the graph in Grafana , where memory leakage of PLC could be detected based on its memory column. This particular CSV file generated based on user inputs - if user required every 5 seconds intervals or every 1 minutes intervals or 1 hour so on. currently i have generated in seconds to check .

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [3 August 2022 03:29 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/29 "2022-08-03T03:29:34Z")

</div>

Its not entirely PLC IO data , rather than its Diag data. So to generate a Diag data , i have to run the PLC tools in windows command prompt environment ( with certain key combination). so thats how this csv file getting generated. i know its going around but this is how manufacture did

---

<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:** [3 August 2022 13:22 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/30 "2022-08-03T13:22:26Z")

</div>

> [@Ferdi84](#):
>
> my final aim to plot the graph in Grafana

Graph of what?

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [4 August 2022 03:50 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/31 "2022-08-04T03:50:56Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d5cfab432840caeceee016e2050d1a012624980f.png)  
something like , memory allocated and analyze any abnormality

---

<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:** [4 August 2022 08:29 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/32 "2022-08-04T08:29:28Z")

</div>

In that case you need to put the plc time time into the `time` field in the database.

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [8 August 2022 08:57 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/34 "2022-08-08T08:57:12Z")

</div>

I have tried , but it doesnt replace the time field

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [8 August 2022 09:09 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/35 "2022-08-08T09:09:35Z")

</div>

and got the error like below

Error: Expected numeric value for, timestamp, but got '9/29/2020 23:53'!

---

<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:** [9 August 2022 10:45 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/36 "2022-08-09T10:45:47Z")

</div>

If you go to the node's github page it shows examples of valid timestamp formats.

---

<div class="post-metadata">

**Author:** ![Ferdi84](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Ferdi84](https://discourse.nodered.org/u/Ferdi84)\
**Post date:** [29 August 2022 03:39 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/37 "2022-08-29T03:39:53Z")

</div>

i could able to insert like below into Influx DB  
\_time: new Date(msg.payload.PlcTime)

---

<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:** [12 September 2022 03:40 UTC](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886/38 "2022-09-12T03:40:43Z")

</div>

Closed on 12 September 2022 03:40 UTC

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

[Previous page](https://discourse.nodered.org/t/reading-from-csv-file-insert-values-into-influx-db/65886.md?page=1)
