Node-RED data to influxDB

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.

[
    {
        "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": ""
    }
]
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"}

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 you will see why it's being rejected.

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.

What it states:

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

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

Is that a string or an array ?

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

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.

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

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

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.

2 Likes

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?

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

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