# Node-Red data showing NaN

**URL:** <https://discourse.nodered.org/t/node-red-data-showing-nan/59519>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [8 March 2022 01:23 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519 "2022-03-08T01:23:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![weishoose](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@weishoose](https://discourse.nodered.org/u/weishoose)\
**Post date:** [8 March 2022 01:23 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/1 "2022-03-08T01:23:52Z")

</div>

Hello everybody!

I'm new to Node-Red so please go easy on me 🙂

I am trying to populate sensor data collected from an Arduino on to google sheets using Node-Red. However, the sensor data comes out as NaN all the time.

I've made sure to have my Arduino data come out in JSON format.

Please tell me where i went wrong

```auto
[
    {
        "id": "3a5ea13849faccec",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "ed5bdc1bbfa436e9",
        "type": "serial in",
        "z": "3a5ea13849faccec",
        "name": "ghARD",
        "serial": "fc4c36463f1c3b45",
        "x": 210,
        "y": 140,
        "wires": [
            [
                "59c9a7d0c6cbb8dd"
            ]
        ]
    },
    {
        "id": "59c9a7d0c6cbb8dd",
        "type": "json",
        "z": "3a5ea13849faccec",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 370,
        "y": 140,
        "wires": [
            [
                "fa4e033682da9e8a",
                "4664a32c8bf03024",
                "08307f51761c60e7"
            ]
        ]
    },
    {
        "id": "c3b261b41476b5ea",
        "type": "inject",
        "z": "3a5ea13849faccec",
        "name": "2s Counter",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "2",
        "crontab": "",
        "once": true,
        "onceDelay": "2",
        "topic": "",
        "payloadType": "date",
        "x": 270,
        "y": 400,
        "wires": [
            [
                "6657077ae35e3eb7"
            ]
        ]
    },
    {
        "id": "6657077ae35e3eb7",
        "type": "function",
        "z": "3a5ea13849faccec",
        "name": "",
        "func": "var ghARD = flow.get('ghARD')||{\"MoistureValue\":0, \"hum\":0, \"temp\":0, \"phValue\":0,\"light_intentsity\":0, \"count\":0};\n\nvar output = new Array(6);\n\noutput[0] = new Date();\noutput[0].setHours(output[0].getHours()+8);\noutput[1] = Math.round(ghARD.MoistureValue/ghARD.count);\noutput[2] = Math.round(ghARD.hum/ghARD.count);\noutput[3] = Math.round(ghARD.temp/ghARD.count);\noutput[4] = Math.round(ghARD.phValue/ghARD.count);\noutput[5] = Math.round(ghARD.light_intensity/ghARD.count);\n\nflow.set('ghARD',{\"MoistureValue\":0, \"hum\":0, \"temp\":0, \"phValue\":0,\"light_intentsity\":0, \"count\":0});\n\nmsg.payload = output;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "5091f180495e94f8",
        "type": "GSheet",
        "z": "3a5ea13849faccec",
        "creds": "34b64851ad69da8f",
        "method": "append",
        "action": "",
        "sheet": "1WQDeAQET3ZA-nVZ89tmNycOpvItl7_k8CSzZJUtUU80",
        "cells": "Datasheet!A:Z",
        "flatten": false,
        "name": "",
        "x": 1130,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "fa4e033682da9e8a",
        "type": "mqtt out",
        "z": "3a5ea13849faccec",
        "name": "",
        "topic": "ghARD",
        "qos": "2",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "ca2321cc.9faff",
        "x": 680,
        "y": 180,
        "wires": []
    },
    {
        "id": "4664a32c8bf03024",
        "type": "debug",
        "z": "3a5ea13849faccec",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 100,
        "wires": []
    },
    {
        "id": "08307f51761c60e7",
        "type": "function",
        "z": "3a5ea13849faccec",
        "name": "",
        "func": "var ghARD = flow.get('ghARD')||{\"MoistureValue\":0, \"hum\":0, \"temp\":0, \"phValue\":0, \"light_intensity\":0, \"count\":0};\n\nghARD.MoistureValue += msg.payload.MoistureValue;\nghARD.hum += msg.payload.hum;\nghARD.temp += msg.payload.temp;\nghARD.phValue += light_intensity;\nghARD.count += 1;\nflow.set('ghARD',ghARD);\n\nreturn ghARD;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "93204e69d7aea425",
        "type": "debug",
        "z": "3a5ea13849faccec",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 400,
        "wires": []
    },
    {
        "id": "fc4c36463f1c3b45",
        "type": "serial-port",
        "serialport": "COM9",
        "serialbaud": "57600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    },
    {
        "id": "34b64851ad69da8f",
        "type": "gauth",
        "name": "greenhouse@green-house-340803.iam.gserviceaccount.com"
    },
    {
        "id": "ca2321cc.9faff",
        "type": "mqtt-broker",
        "name": "",
        "broker": "tcp://broker.hivemq.com",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 March 2022 05:45 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/2 "2022-03-08T05:45:02Z")

</div>

Hi.

Just something you should do:

Try to make a smaller flow that only causes the problem you have.

Get rid of the extra nodes.

Have an `inject` node that injects the value you think is in the file.  
Inject that into the node that gives the error. See what happens.

If that works, then change the flow slightly so you read in from the file and pass the value to the node. See what happens.

One thing to be aware of is the _type_ of variable it is.  
If you (by what ever means) write a _string_ value to the vile there's your problem.

One way around this is to read the file and convert the value read to an integer.

Look for `parseINT()`

---

<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:** [8 March 2022 07:15 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/3 "2022-03-08T07:15:08Z")

</div>

Welcome to the forum @weishoose

I can't look at your flow at the moment, but what you need to do is to start where the data comes into node red and use debug nodes to check it is what you expect. If that is correct then move past the next node in the flow and check it is correct there, and so on.

Once you work out exactly where it is failing, if you can't understand why, then show us what is going into that node and what is coming out so we can help.

---

<div class="post-metadata">

**Author:** ![weishoose](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@weishoose](https://discourse.nodered.org/u/weishoose)\
**Post date:** [8 March 2022 08:08 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/4 "2022-03-08T08:08:46Z")

</div>

Thank you for the reply!

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8b3e974d41f6c0da2883aa058d2854057a0538f.png)  
 ![Capture1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00e8299785fb987fd679eb874ebce883aab33e4c.png)

It seems like the problem is coming from the data coming out from my Arduino. However my data is already arranged in JSON format.

Is my data formatted properly? or am i missing something?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [8 March 2022 08:12 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/5 "2022-03-08T08:12:12Z")

</div>

Add the Debug node to the output of the serial node so we can see what it is recieving and in what format.

What version of Node-RED are you using?

---

<div class="post-metadata">

**Author:** ![weishoose](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@weishoose](https://discourse.nodered.org/u/weishoose)\
**Post date:** [8 March 2022 09:04 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/6 "2022-03-08T09:04:38Z")

</div>

Hi Knolleary,

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/707664ea6c448176028bd11375551226ee65bca9.png)  
This is what I get when i connect the Serial Out to the debug node. A string which contains my sensor data.

However, when i connect Serial Out \> json \> Debug, it shows "Ignored non object payload"

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 March 2022 09:06 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/7 "2022-03-08T09:06:22Z")

</div>

If it is the first one, that is an array.  
So you will have to look at / parse `msg.payload[x]` where `x` points to the part of the array you want to use.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [8 March 2022 09:12 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/8 "2022-03-08T09:12:29Z")

</div>

> [@weishoose](#):
>
> However, when i connect Serial Out \> json \> Debug, it shows "Ignored non object payload"

And what version of Node-RED are you using?

The problem is the payload coming out of the Serial node is a `Buffer` object, not a String.

Node-RED 2.2 included an update for the JSON node that would allow it to handle Buffer type payloads.

On earlier versions, you would have to add a Function node after the Serial node to convert the Buffer to a String:

```auto
msg.payload = msg.payload.toString()
return msg

```

---

<div class="post-metadata">

**Author:** ![weishoose](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@weishoose](https://discourse.nodered.org/u/weishoose)\
**Post date:** [8 March 2022 09:20 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/9 "2022-03-08T09:20:22Z")

</div>

This worked! I updated node-red and my data begun populating.

You have no idea how happy i am right now. Thank you! I really appreciate it

---

<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:** [22 March 2022 09:21 UTC](https://discourse.nodered.org/t/node-red-data-showing-nan/59519/10 "2022-03-22T09:21:08Z")

</div>

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