Trying to add timestamp to output of ping

I'm working on my second flow ever. Trying to add a timestamp to output of ping before I store it in a file. What did I do wrong?

Node Red v3.0.2 running on a Pi2.

Thanks,

[
    {
        "id": "99ef514ed8f83fb0",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f9bf451785ed5e44",
        "type": "ping",
        "z": "99ef514ed8f83fb0",
        "protocol": "IPv4",
        "mode": "timed",
        "name": "IsMyPhoneHome",
        "host": "192.168.1.129",
        "timer": "60",
        "inputs": 0,
        "x": 200,
        "y": 120,
        "wires": [
            [
                "26eb2ed06669929e"
            ]
        ]
    },
    {
        "id": "02821fe1a125e4f1",
        "type": "debug",
        "z": "99ef514ed8f83fb0",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 120,
        "wires": []
    },
    {
        "id": "8422207d09edcb9d",
        "type": "file",
        "z": "99ef514ed8f83fb0",
        "name": "PhoneHome",
        "filename": "/home/pi/phonehome.txt",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 570,
        "y": 120,
        "wires": [
            [
                "02821fe1a125e4f1"
            ]
        ]
    },
    {
        "id": "26eb2ed06669929e",
        "type": "function",
        "z": "99ef514ed8f83fb0",
        "name": "AddTime2",
        "func": "msg.payload.Time = new Date()\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 380,
        "y": 120,
        "wires": [
            [
                "8422207d09edcb9d"
            ]
        ]
    }
]

In your function node msg.payload is a string but you are trying to use it as an object. One way to do this would be to use a change node to convert msg.payload to an object and add the time to like this:

Screenshot 2023-01-02 at 8.28.53 PM

You should do a google search using 'javascript what is an object' and do some learning :slightly_smiling_face:

you could also use the node 'node-red-contrib-simpletime'. This inserts the desired times/date configurable.

BR
Hubertus

Thank you for helping. I think that inserts epoch or unix time. It worked. I know I have a lot to learn but I'm retiring soon and I'll have time.

I did not try it yet, but I see it gives me some options.

Thanks,

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