Trying to save JSON to influxdb

Hey there
I,m trying to save some data manually to my influxdb:
(inject node)<-->(function node)<-->(influxdb out node)
Here's my function node contents:

msg.payload = {
    "spec": 10,
    "right": 9,
    "left": 11
}
return msg;

The problem is that it seems that data is not added to influxdb but it is overwritten. I don't know what I'm doing wrong and whether this is a node-red related problem or influxdb related.
Do you guys have any ideas on this matter?

Welcome to the forum @xubin

That should certainly add a new point to the database. How do you know it is overwriting data rather than adding to it?

Please select the inject node and the influx node and Export them (CTRL+E or use the menu) and paste here.

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

``` 
   code goes here 
```

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

Thanks @Colin
I check my DB after each inject, since the time of each record gets updated I suppose that data is overwritten.

Here's my flow:

[
    {
        "id": "d6917e29a170d08e",
        "type": "inject",
        "z": "20c088228d07a2a4",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 120,
        "wires": [
            [
                "457bbc90b7b71e12"
            ]
        ]
    },
    {
        "id": "457bbc90b7b71e12",
        "type": "function",
        "z": "20c088228d07a2a4",
        "name": "function 2",
        "func": "msg.payload = [{\n    \"spec\": 10,\n    \"right\": 9,\n    \"left\": 11\n}]\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 120,
        "wires": [
            [
                "49e76f17d94beaeb",
                "f173287b4bbdda06"
            ]
        ]
    },
    {
        "id": "49e76f17d94beaeb",
        "type": "influxdb out",
        "z": "20c088228d07a2a4",
        "influxdb": "781331b7e1a6b50a",
        "name": "",
        "measurement": "cutterc",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "smart-systems",
        "bucket": "beta-95",
        "x": 680,
        "y": 120,
        "wires": []
    },
    {
        "id": "f173287b4bbdda06",
        "type": "debug",
        "z": "20c088228d07a2a4",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 540,
        "y": 40,
        "wires": []
    },
    {
        "id": "781331b7e1a6b50a",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://localhost:8086",
        "timeout": "10",
        "rejectUnauthorized": true
    }
]

You have in the function

msg.payload = [{
    "spec": 10,
    "right": 9,
    "left": 11
}]
return msg;

If you look at the help text for the node, msg.payload should be an object, an array of two objects, or an array of arrays. Your payload is not one of those, it is an array of one object. Take the square brackets out.

How are you doing that? If you still have the problem after fixing the function show us exactly how you are viewing it and what you see.

Thanks @Colin
I change my function to:

msg.payload = {
    "spec": 10,
    "right": 9,
    "left": 11
}
return msg;

But the problem still remains. After the first inject, this is my view in Influxdb webU:


And this is after the second inject with same values:

This is after third inject with values: spec:20 right:30 left:40 :

That's weird! You can check my flow which I copied earlier. There is nothing complex in this flow but I can not figure out the problem!

Note:
image
The important word is 'mean'.
and
image

I don't use the Data Explorer, but that suggests to me that the query is taking the average values over each hour, which explains the values shown I think.

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