Node-Red -> Infuxdb - Timestamp out of date

I am using Raspberry 4 to run Node-Red, Influxdb and Grafana.

The Pi is set up on Johannasburg South Africa time zone.

The problem if I query the data are a few hours off, I suspect somehow the data are stored with the incorrect time stamp.

Any one have an idea where to look for how this happens?

image

Using a test flow in Node-Red

[
    {
        "id": "1bc44ad459ce827a",
        "type": "debug",
        "z": "639ef7b5796c2a80",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 900,
        "wires": []
    },
    {
        "id": "6d62d916ff2d2685",
        "type": "inject",
        "z": "639ef7b5796c2a80",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "10",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 290,
        "y": 940,
        "wires": [
            [
                "22d1b43de61de6d3"
            ]
        ]
    },
    {
        "id": "22d1b43de61de6d3",
        "type": "change",
        "z": "639ef7b5796c2a80",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "Temperature",
                "pt": "global",
                "to": "50*$random()",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "Density",
                "pt": "global",
                "to": "1000*$random()",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "timestamp",
                "pt": "global",
                "to": "",
                "tot": "date"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 940,
        "wires": [
            [
                "04c946e6a479bb97"
            ]
        ]
    },
    {
        "id": "04c946e6a479bb97",
        "type": "function",
        "z": "639ef7b5796c2a80",
        "name": "function 2",
        "func": "let dens = global.get('Density')\nlet temp = global.get('Temperature')\nlet timestamp = global.get('timestamp')\n\nmsg.payload = {\n    \"Temerature\":  temp,\n    \"Dencity\": dens\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 940,
        "wires": [
            [
                "1bc44ad459ce827a",
                "349f7178fe25791a"
            ]
        ]
    },
    {
        "id": "349f7178fe25791a",
        "type": "influxdb out",
        "z": "639ef7b5796c2a80",
        "influxdb": "01d768772babdcd3",
        "name": "co2",
        "measurement": "sas",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ns",
        "retentionPolicyV18Flux": "",
        "org": "SOIOT",
        "bucket": "temp",
        "x": 890,
        "y": 940,
        "wires": []
    },
    {
        "id": "01d768772babdcd3",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "CO2",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://localhost:8086",
        "rejectUnauthorized": false
    }
]

Are you running NR in Docker? If so, the TZ environment variables might be wrong or not set. I've recently discovered that the time zone in a container is not forced to be the same as the host machine without a TZ variable in your docker config..

Have a look at this topic, looks like the same problem.

I don't think it is the problem in the other thread, that was specifically the influxdb explorer tool that was showing confusing timestamps. This is showing it in grafana.

@ScheepersJohan as well as answering the docker question, what timezone is the machine running the browser set to?

Ok found the problem.

It is the Influxdb node 'node-red-contrib-influxdb' can not be stet to nanosecond for the precision, not that I needed it to that accuracy.

Problem solve by setting to microsecond.

image

Thank you for everyone's input.

Since you are letting influx add the timestamps that should not make any difference, unless you started with it in nanosecs, recorded some data, and then changed it, which might mess things up I suppose.
If, starting from scratch, it does make a difference then that is a bug that you should report.

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