Reading from CSV file insert values into influx-DB

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

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

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

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.

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

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

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?

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

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 .

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

Graph of what?


something like , memory allocated and analyze any abnormality

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

I have tried , but it doesnt replace the time field

and got the error like below

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

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

1 Like

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

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