# Node-RED data to influxDB

**URL:** <https://discourse.nodered.org/t/node-red-data-to-influxdb/16737>\
**Category:** General\
**Created:** [15 October 2019 16:41 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737 "2019-10-15T16:41:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://discourse.nodered.org/u/Bond)\
**Post date:** [15 October 2019 16:41 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/1 "2019-10-15T16:41:44Z")

</div>

I decoded data string from TZ-035 Receiver and got all the data. However, when i try to get my data into influxDB. I have a 404 error shown below. I tried a few ways but dont know how to get it correct. Anyone know how to do it please help me.

```auto
[
    {
        "id": "45bf52bb.b0e994",
        "type": "serial in",
        "z": "5b261e0a.419d8",
        "name": "tzone_receiver",
        "serial": "b1d5fe5f.f69be8",
        "x": 160.01417922973633,
        "y": 68.20563220977783,
        "wires": [
            [
                "720b3858.e2e988"
            ]
        ]
    },
    {
        "id": "13dff4d3.2fdd5b",
        "type": "inject",
        "z": "5b261e0a.419d8",
        "name": "simulate TZ data",
        "topic": "",
        "payload": "7E 0D 12 34 56 62 16 01 79 00 0E 10 00 EC 4F 72 03",
        "payloadType": "str",
        "repeat": "30",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "x": 230.01419830322266,
        "y": 267.00565338134766,
        "wires": [
            [
                "720b3858.e2e988"
            ]
        ]
    },
    {
        "id": "9796384c.102778",
        "type": "debug",
        "z": "5b261e0a.419d8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 868.0142440795898,
        "y": 380.0056343078613,
        "wires": []
    },
    {
        "id": "720b3858.e2e988",
        "type": "function",
        "z": "5b261e0a.419d8",
        "name": "Parse data",
        "func": "let parsed = {} \nlet p = msg.payload\nparsed.parts = p.split(\" \");\nparsed.data = p;\nparsed.datalength = parseInt(parsed.parts[1],16);\n\nparsed.id = parsed.parts[2] + parsed.parts[3] + parsed.parts[4] + parsed.parts[5];\n\nparsed.tagStatus = parseInt(parsed.parts[6] ,16);\n\nvar batteryVoltage = parseInt(parsed.parts[7] + parsed.parts[8] ,16);\nparsed.batteryVoltage = batteryVoltage/1000;\n\nvar temperature = parseInt(parsed.parts[9] + parsed.parts[10] ,16);\nparsed.temperature = temperature / 10;\n\nparsed.humidity = parseInt(parsed.parts[11],16);\n\nparsed.RSSI = parseInt(parsed.parts[12],16);\n\nparsed.checkCode = parseInt(parsed.parts[13],16);\n\nparsed.EndCode = parseInt(parsed.parts[14],16);\n\nmsg.payload = parsed\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "x": 560.0142288208008,
        "y": 207.00563430786133,
        "wires": [
            [
                "9796384c.102778",
                "f66be072.6f143"
            ]
        ]
    },
    {
        "id": "f66be072.6f143",
        "type": "influxdb out",
        "z": "5b261e0a.419d8",
        "influxdb": "5ae4f0be.6f3d9",
        "name": "monitor",
        "measurement": "mystation",
        "precision": "",
        "retentionPolicy": "",
        "x": 889.0142021179199,
        "y": 509.0056858062744,
        "wires": []
    },
    {
        "id": "b1d5fe5f.f69be8",
        "type": "serial-port",
        "z": "",
        "serialport": "/dev/ttyUSB0",
        "serialbaud": "115200",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": false,
        "responsetimeout": "10000"
    },
    {
        "id": "5ae4f0be.6f3d9",
        "type": "influxdb",
        "z": "",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "MONITOR",
        "name": "monitor",
        "usetls": false,
        "tls": ""
    }
]

```

```auto
Error: A 400 Bad Request error occurred: {"error":"unable to parse 'mystation EndCode=3,RSSI=28,batteryVoltage=3.531,checkCode=35,data=\"7E 0B 62 18 01 16 00 0D CB 00 DE 37 1C 23 03 \r\n\",datalength=11,humidity=55,id=\"62180116\",parts=7E,0B,62,18,01,16,00,0D,CB,00,DE,37,1C,23,03,\r': invalid float\nunable to parse ',tagStatus=0,temperature=22.2': missing measurement"}

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [15 October 2019 18:08 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/3 "2019-10-15T18:08:07Z")

</div>

The data format originating from the function node and feeding into the influxdb node is not being presented in the correct format.

If you replace the influxdb node with a debug node, and compare your format with the acceptable format examples in the node readme - [https://flows.nodered.org/node/node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb) you will see why it's being rejected.

---

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://discourse.nodered.org/u/Bond)\
**Post date:** [16 October 2019 07:53 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/4 "2019-10-16T07:53:25Z")

</div>

Sorry i'm new to this, i tried to follow the example but dont know where did i get wrong. I formatted my data with name and value already.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 October 2019 08:08 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/5 "2019-10-16T08:08:56Z")

</div>

What it states:

> [@Bond](#):
>
> invalid float

Somewhere you are trying to insert something other than a float.  
And looking at:

```auto
parts=7E,0B,62,18,01,16,00,0D,CB,00,DE,37,1C,23,03,

```

Is that a string or an array ?

---

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://discourse.nodered.org/u/Bond)\
**Post date:** [16 October 2019 09:02 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/6 "2019-10-16T09:02:30Z")

</div>

hi bakman2,  
The string i tried to insert is exactly what my sensors give out. And it is an array.

---

<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:** [16 October 2019 10:07 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/7 "2019-10-16T10:07:04Z")

</div>

It can't be a string and an array, it may be a string representing an array, but it is not an array if it is a string. Feed what you are sending to the influx node into a debug node and see if it looks right. If it does look right to you then screenshot or copy/paste the debug output here.

---

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://discourse.nodered.org/u/Bond)\
**Post date:** [17 October 2019 01:55 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/8 "2019-10-17T01:55:50Z")

</div>

I copy the debug node in the flow already. You can see what i’m trying to send there.

---

<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:** [17 October 2019 08:14 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/9 "2019-10-17T08:14:25Z")

</div>

In the info for the influxdb node it describes how it interprets the contents on msg.payload based on the type of msg.payload. The options are

1. **msg.payload** is a string, number, or boolean
2. **msg.payload** is an object containing multiple properties
3. **msg.payload** is an array of arrays

For the benefit of those who do not wish to go to the effort of importing the flow and running it as I have had to do, a debug node showing msg.payload shows

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/ce8450feb8fa9c5f74f9318f2e65720724f47b35.png)

So msg.payload is an object containing multiple properties.  
For that case the info tab says

If **msg.payload** is an object containing multiple properties, the fields will be written to the measurement.

What that means is that each property in the object is expected to be a field whose value will be written to the database. In addition to the fields that I assume you do want to write to the database it also has properties `parts, data and datalength`. Influxdb does not know what to do with the property `parts` as that is an array, hence the error you are getting.

---

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://discourse.nodered.org/u/Bond)\
**Post date:** [17 October 2019 08:33 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/10 "2019-10-17T08:33:19Z")

</div>

So if i want to get away from the error, i should create another function to filter out the `parts` and only show in the `msg.payload` what i want to write to the `influxdb`. Is that right?

---

<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:** [17 October 2019 08:37 UTC](https://discourse.nodered.org/t/node-red-data-to-influxdb/16737/11 "2019-10-17T08:37:49Z")

</div>

No need to filter them out, just don't put them in in the first place. Declare those as local variables, not as members of parsed

```auto
let parsed = {} 
let p = msg.payload
let.parts = p.split(" ");
let data = p;
let datalength = parseInt(parts[1],16);
etc

```
