Payload name - not going through function node

Hello All,

I am using the below code in a function node. When it goes in it is - msg.payload.col6. When it comes out it seems to be stripped of the name and it's just payload. I'm putting 2 functions nodes and a change node into a join node and trying to do a calculation with the three outputs in another function node, but don't seem to be able to as the 2 function nodes are both payload with nothing else. What am I doing wrong please if anyone can help.

var t = msg.payload.col6;

var LSVP = (Math.pow(2.71828,(t / (t +238.3) * 17.2694))* 610.78)/1000;

msg.payload=LSVP;
return msg;

This code wipes out the content of what was in msg.payload. You might want to use
msg.payload.lsvp = LSVP;

1 Like

Ahh I was going to tell you that you needed to fix the flow but I see you have removed it. Did you solve your issue?

P.S.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Thank you very much for your reply. I haven't yet got a solution. I'll do the code again. Thanks

[
    {
        "id": "f689f3fda0f0c8b7",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9d3e060be4525873",
        "type": "csv",
        "z": "f689f3fda0f0c8b7",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 370,
        "y": 280,
        "wires": [
            [
                "4a94aead22732ee2",
                "300b476c220c7d9a",
                "939dc8f55f8a7cf6"
            ]
        ]
    },
    {
        "id": "4a94aead22732ee2",
        "type": "change",
        "z": "f689f3fda0f0c8b7",
        "name": "temp 1",
        "rules": [
            {
                "t": "set",
                "p": "payload.col1",
                "pt": "msg",
                "to": "",
                "tot": "date"
            },
            {
                "t": "delete",
                "p": "payload.col2",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col4",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col5",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col3",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col7",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col8",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col9",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col10",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col11",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col12",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col13",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col14",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col15",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col16",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 280,
        "wires": [
            [
                "c519f951a59ae2bd"
            ]
        ]
    },
    {
        "id": "300b476c220c7d9a",
        "type": "change",
        "z": "f689f3fda0f0c8b7",
        "name": "temp 2",
        "rules": [
            {
                "t": "set",
                "p": "payload.col1",
                "pt": "msg",
                "to": "",
                "tot": "date"
            },
            {
                "t": "delete",
                "p": "payload.col2",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col4",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col5",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col6",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col7",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col8",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col9",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col3",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col11",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col12",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col13",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col14",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col15",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col16",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 320,
        "wires": [
            [
                "d1cb0640f12c8067"
            ]
        ]
    },
    {
        "id": "d1cb0640f12c8067",
        "type": "function",
        "z": "f689f3fda0f0c8b7",
        "name": "SVP",
        "func": "var t = msg.payload.col10;\n\nvar SVP = (Math.pow(2.71828,(t / (t +238.3) * 17.2694))* 610.78)/1000;\n\nmsg.payload.svp = SVP;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 320,
        "wires": [
            [
                "a56da7c67106b920"
            ]
        ]
    },
    {
        "id": "a56da7c67106b920",
        "type": "join",
        "z": "f689f3fda0f0c8b7",
        "name": "",
        "mode": "auto",
        "build": "string",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 890,
        "y": 320,
        "wires": [
            [
                "5d492c397a9f9f47"
            ]
        ]
    },
    {
        "id": "c519f951a59ae2bd",
        "type": "function",
        "z": "f689f3fda0f0c8b7",
        "name": "LSVP",
        "func": "var t = msg.payload.col6;\n\nvar LSVP = (Math.pow(2.71828,(t / (t +238.3) * 17.2694))* 610.78)/1000;\n\nmsg.payload.lsvp = LSVP;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 280,
        "wires": [
            [
                "a56da7c67106b920"
            ]
        ]
    },
    {
        "id": "5d492c397a9f9f47",
        "type": "function",
        "z": "f689f3fda0f0c8b7",
        "name": "DDP",
        "func": "var l = msg.payload.lsvp;\nvar t = msg.payload.svp;\nvar h = msg.payload.col11;\n\nvar DDP = l-(t*h/100);\n\nmsg.payload=DDP\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 320,
        "wires": [
            [
                "d1037a4b58b60f69"
            ]
        ]
    },
    {
        "id": "d1037a4b58b60f69",
        "type": "debug",
        "z": "f689f3fda0f0c8b7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1010,
        "y": 400,
        "wires": []
    },
    {
        "id": "2d741eeba951eccc",
        "type": "tail",
        "z": "f689f3fda0f0c8b7",
        "name": "",
        "filetype": "text",
        "split": "[\\r]{0,1}\\n",
        "filename": "/home/pi/Downloads/20220525.csv",
        "inputs": 0,
        "x": 140,
        "y": 280,
        "wires": [
            [
                "9d3e060be4525873"
            ]
        ]
    },
    {
        "id": "07ff13bb448c7da9",
        "type": "calculator",
        "z": "f689f3fda0f0c8b7",
        "name": "x 100",
        "inputMsgField": "payload.col11",
        "outputMsgField": "payload.col11",
        "operation": "mult",
        "constant": "100",
        "round": true,
        "decimals": "1",
        "x": 730,
        "y": 360,
        "wires": [
            [
                "a56da7c67106b920"
            ]
        ]
    },
    {
        "id": "939dc8f55f8a7cf6",
        "type": "change",
        "z": "f689f3fda0f0c8b7",
        "name": "Humidity",
        "rules": [
            {
                "t": "set",
                "p": "payload.col1",
                "pt": "msg",
                "to": "",
                "tot": "date"
            },
            {
                "t": "delete",
                "p": "payload.col2",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col4",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col5",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col6",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col7",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col8",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col9",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col10",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col3",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col12",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col13",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col14",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col15",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload.col16",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 360,
        "wires": [
            [
                "07ff13bb448c7da9"
            ]
        ]
    }
]

can you provide a small sample of the data, say 10 rows?

also add seperate debug node (set to display the complete msg object) to the output of each of the function nodes 'LSVP', 'SVP' and 'x 100' and look at the parts section of each output. What do you see?

Morning, I've put the last ten entries in the code below.

The first node reads the entry when its written into the local cvs file.

I'm super new to this so probably made a total pigs ear of the way I did it.

2022/05/26 00:06:19,1,0.058,-0.087,2,21.3957,20.8076,3,1.409,22.1,0.529,101.73,4,1829.59,20.6,0.0
2022/05/26 00:06:53,1,-0.074,0.024,2,21.3161,20.8079,3,1.409,22.1,0.529,101.73,4,1829.87,20.6,0.0
2022/05/26 00:07:28,1,0.008,-0.13,2,21.278,20.8079,3,1.41,22.1,0.529,101.73,4,1829.69,20.6,0.0
2022/05/26 00:08:02,1,-0.049,-0.148,2,21.2188,20.8078,3,1.41,22.1,0.529,101.73,4,1829.15,20.6,0.0
2022/05/26 00:08:36,1,0.074,-0.111,2,21.3127,20.808,3,1.41,22.1,0.529,101.73,4,1829.38,20.6,0.0
2022/05/26 00:09:11,1,0.058,-0.179,2,21.271,20.8079,3,1.41,22.1,0.529,101.73,4,1829.73,20.6,0.0
2022/05/26 00:09:45,1,0.025,-0.16,2,21.2988,20.8079,3,1.411,22.2,0.529,101.73,4,1829.44,20.6,0.0
2022/05/26 00:10:20,1,-0.016,-0.148,2,21.3507,20.8078,3,1.41,22.2,0.529,101.73,4,1829.17,20.6,0.0
2022/05/26 00:10:54,1,0.025,-0.173,2,21.337,20.8079,3,1.41,22.2,0.529,101.73,4,1829.13,20.6,0.0
2022/05/26 00:11:28,1,0.107,-0.093,2,21.2083,20.8078,3,1.411,22.2,0.529,101.73,4,1829.63,20.6,0.0
2022/05/26 00:12:03,1,-0.016,-0.099,2,21.2081,20.8076,3,1.411,22.2,0.529,101.73,4,1829.23,20.6,0.0
2022/05/26 00:12:37,1,0.099,-0.154,2,21.2255,20.8076,3,1.412,22.2,0.529,101.73,4,1829.49,20.6,0.0
2022/05/26 00:13:11,1,0.041,-0.197,2,21.2117,20.8077,3,1.412,22.2,0.528,101.73,4,1829.64,20.6,0.0

Ok, you did not set the debug nodes to display the 'complete msg object'
complete_msg_object

It looks like you are trying to process the data of a couple of the columns in each row. If that correct, please explain why you are manually splitting and trying to join the data.

What is the final output you want?

Just got back.

I'm splitting the data as I need to do different calculations on different bits and thought that the best way? It's joined again to do a calculation of the results of the previous.

This isn't all of the flow. I only put in the bit that doesn't work to avoid confusion. It seems though I am doing something quite wrong?

Here is the debug set as you asked -

Screen Shot 2022-05-26 at 22.36.10

Sorry I have only been doing this for some weeks now and muddling my way through it.

If all the data is in the same row you don’t need to create three paths and eventually do a join. You could do the calculation in just one function node.

let l = msg.payload.col6;
node.warn("col6="+l);

let t = msg.payload.col10;
node.warn("col10="+t);

let h = msg.payload.col11;
node.warn("col11="+h);

let LSVP = (Math.pow(2.71828,(l / (l +238.3) * 17.2694))* 610.78)/1000;
let SVP  = (Math.pow(2.71828,(t / (t +238.3) * 17.2694))* 610.78)/1000;
    h    = Math.round(h * 100*10)/10;
let DDP = LSVP-(SVP*h/100);

msg.lsvp = LSVP;
msg.svp  = SVP;
msg.h    = h;

msg.payload=DDP
return msg;

send the output of the csv to a function node with the above code and send the putput to a debug node to see the results.

Here is some reading that might make things clearer

Canned replies:

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

I recommend watching this playlist: Node-RED Essentials. 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.

Thank you very much.

I will watch the videos later. Cheers for that. I'm sure it will help me. It will definitely be easier not to split everything!

The code didn't seem to work. I put it in a function node after the cvs node and this was the result -

Screen Shot 2022-05-27 at 18.27.51

Did you add a debug node to the output of the function node?
The ‘node.warn’ statements are there so you can see the values of those variables in the function node. You can comment then or remove them from the code.

I'm not sure what I did, but I didn't add the debug to the function it seems. I was supposed to!

Thank you so much for your help. I added the rest of the inputs to the function node and did calculations on them or passed them through and it all seems to be working great. I now have 11 parts in the debug all with the correct values. Your example made it all make sense (well getting closer)

I need to do a bit of work on it tomorrow - sort timestamp (msg.payload.col1) - sort out the decimals and then send to influxdb. Looking like its going to work.

Thank you so much for your time to help me. Still a little confused to the difference between payload and parts of the message, though not watched all the video links you posted yet.

It's always a good idea to look at the documentation :grin:

Take a look at this: Working with messages : Node-RED

I will do thanks. Should read it first rather than after getting stuck!

Sorted time I think with msg.payload = Date.parse(msg.payload);

I now have 3 nodes instead of 20 :grinning:

2 Likes

A post was split to a new topic: Problems sending data to Influx

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