Import csv data to inluxdb - function node

Hello everyone,
I want to write Data from csv with the following format to a influx db.
Example:
Time,TS1,TS2,RO1,Heatquantity1,Heatquantity2,CO2Savings,Errors
2020-01-02T00:00,3.0,14.6,0,977,977,234,0
How can you program the the function node, to import the fields to the influx database (with timestamp from csv)?

my actual flow:

[
    {
        "id": "a2a16dc6.fbd32",
        "type": "function",
        "z": "66faf3265599a6a5",
        "name": "Ready for next lines",
        "func": "return [\n    msg.complete ? msg : null,\n    { tick: true },\n];\n",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 930,
        "y": 400,
        "wires": [
            [
                "87fbc09b.6deeb",
                "35615002.196b78"
            ],
            [
                "e6ec0f0a.388198"
            ]
        ]
    },
    {
        "id": "436dce51.065f6",
        "type": "csv",
        "z": "66faf3265599a6a5",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "mult",
        "ret": "\\n",
        "temp": "Time,TS1,TS2,RO1,Heatquantity1,Heatquantity2,CO2Savings,Errors",
        "skip": "0",
        "strings": false,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 420,
        "y": 460,
        "wires": [
            [
                "ac588056e821047b"
            ]
        ]
    },
    {
        "id": "87fbc09b.6deeb",
        "type": "debug",
        "z": "66faf3265599a6a5",
        "name": "Done",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "_parts.lines",
        "statusType": "msg",
        "x": 1160,
        "y": 460,
        "wires": []
    },
    {
        "id": "35615002.196b78",
        "type": "ui_text",
        "z": "66faf3265599a6a5",
        "group": "5368deb4.54dba",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Lines uploaded:",
        "format": "{{msg._parts.lines}}",
        "layout": "row-spread",
        "className": "",
        "x": 1190,
        "y": 400,
        "wires": []
    },
    {
        "id": "e6ec0f0a.388198",
        "type": "chunks-to-lines",
        "z": "66faf3265599a6a5",
        "name": "",
        "nbLines": "4096",
        "linesFormat": "csv",
        "decoder": "UTF-8",
        "x": 270,
        "y": 460,
        "wires": [
            [
                "436dce51.065f6"
            ]
        ]
    },
    {
        "id": "4b31cec2.dad2c8",
        "type": "ui_upload",
        "z": "66faf3265599a6a5",
        "group": "5368deb4.54dba",
        "title": "Generic upload to influxdb",
        "name": "uploadinflux",
        "order": 3,
        "width": 6,
        "height": 6,
        "chunk": "256",
        "transfer": "binary",
        "x": 100,
        "y": 460,
        "wires": [
            [
                "e6ec0f0a.388198"
            ]
        ]
    },
    {
        "id": "fb8cb419d5357944",
        "type": "Stackhero-InfluxDB-v2-write",
        "z": "66faf3265599a6a5",
        "server": "48657b1033c65a79",
        "name": "",
        "x": 820,
        "y": 480,
        "wires": [
            [
                "a2a16dc6.fbd32"
            ]
        ]
    },
    {
        "id": "c0a0e415fdd8fb83",
        "type": "debug",
        "z": "66faf3265599a6a5",
        "name": "csv to db",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 570,
        "y": 600,
        "wires": []
    },
    {
        "id": "ac588056e821047b",
        "type": "function",
        "z": "66faf3265599a6a5",
        "name": "format influx",
        "func": "// create object and populate with Influx tags\nvar tags = {}\ntags.node = msg.node\ntags.device = msg.device\ntags.location = msg.location\n\n// create object for measurement values\nvar v = {}\nv.value = msg.payload // the measurement value\n\n// create and fill array for the payload\nvar arr = [] \narr[0] = v            // the measurement value\narr[1] = tags\n\n// put the array into msg.payload and send it off\nmsg.payload = arr\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 590,
        "y": 480,
        "wires": [
            [
                "fb8cb419d5357944",
                "c0a0e415fdd8fb83"
            ]
        ]
    },
    {
        "id": "5368deb4.54dba",
        "type": "ui_group",
        "name": "Außen",
        "tab": "9b1688bfbf5d67fb",
        "order": 4,
        "disp": true,
        "width": "9"
    },
    {
        "id": "48657b1033c65a79",
        "type": "Stackhero-InfluxDB-v2-Server",
        "name": "Test",
        "host": "192.168.172.221",
        "port": "8086",
        "tls": false,
        "credentials": {},
        "info": "SHOW SERIES"
    },
    {
        "id": "9b1688bfbf5d67fb",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Can someone help please?
Thank You
Holger

It appears that you are not using the usual influx nodes (node-red-contrib-influxdb). I have no experience with the stackhero version. Is there a reason you are using that node?

no reason, but i use influxdb 2. I am happy with any solution which one works ;).
Thanks

The usual influx node supports v2.
Show us what the data you have going into your function node looks like in a debug node, and tell us what format data you think needs to be passed to the Influx node.

that is the output from csv node:


that is the actual input for db:

How can I set up the node?

// create object and populate with Influx tags
var tags = {}
tags.node = msg.node
tags.device = msg.device
tags.location = msg.location

// create object for measurement values
var v = {}
v.value = msg.payload // the measurement value

// create and fill array for the payload
var arr = [] 
arr[0] = v            // the measurement value
arr[1] = tags

// put the array into msg.payload and send it off
msg.payload = arr
return msg;

Thank You

I don't see those in the message in the debug pane.

Exactly what message are you trying to send to the influx node.

Also the debug you showed has only one row in it, will it always be just one row in a message?

The function node is a "empty Template".
The csv contains normally up to 1008 rows. The used example contains only one row.
For 7 Readings (TS1,TS2,RO1,Heatquantity1,Heatquantity2,CO2Savings,Errors) with a timestamp.

grafik

Where does the device id come from?
Is the measurement fixed?

Device ID is a defined value. After some issues with influx db Ver 2 (RaspiOS 64, Docker), I went to back to version 1.8 for influx. With my "Test Flow" for writing to db i get now a Error Message with the measurement (see Screenshot). I don`t know why.

What type is node Test1111? How is it configured and what message are you sending to it?

Test1111 is one my databases

this is the readout of debug csv line:


and want to write the related values to influx (timestamp (Time), TS1 3.0...)

I presume it is a node that uses the database, but that doesn't tell us much. If you have a simple test flow that exhibits the problem you are seeing then please export just the required nodes and paste it here.

It is difficult to see how the error you showed could come from the message you posted. In particular, I don't see any reference to solar data there.

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