Ip advanced loop msg.host

I have array with ip

[{"nazwa":"T1","ip":"10.0.0.71","opis_ip_alarm":"ip alarm 1"},{"nazwa":"T2","ip":"10.0.0.72","opis_ip_alarm":null}]

how loop msg.host by ip
I try this

[
    {
        "id": "4f61a7737e17d8d3",
        "type": "adv ping",
        "z": "e79cd8495882236e",
        "name": "",
        "host": "",
        "x": 450,
        "y": 160,
        "wires": [
            [
                "549a4d06d5505586",
                "6cab19e646867a6b"
            ]
        ]
    },
    {
        "id": "20bdc2a9b89d78ca",
        "type": "function",
        "z": "e79cd8495882236e",
        "name": "",
        "func": "var ip = msg.payload;\nvar query = [];\n\nfor (var i = 0; i < ip.length; i++) {\n query[i]=ip[i].ip\n}\nmsg.query.forEach(query => node.send({host: query}))\n\nmsg.ip = query;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 160,
        "wires": [
            [
                "4f61a7737e17d8d3"
            ]
        ]
    },
    {
        "id": "62bb480eeab3e30e",
        "type": "inject",
        "z": "e79cd8495882236e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"nazwa\":\"T1\",\"ip\":\"10.0.0.71\",\"opis_ip_alarm\":\"ip alarm 1\"},{\"nazwa\":\"T2\",\"ip\":\"10.0.0.72\",\"opis_ip_alarm\":null}]",
        "payloadType": "json",
        "x": 90,
        "y": 160,
        "wires": [
            [
                "20bdc2a9b89d78ca"
            ]
        ]
    },
    {
        "id": "549a4d06d5505586",
        "type": "debug",
        "z": "e79cd8495882236e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 160,
        "wires": []
    }
]

obraz

the quick answer is Dont Loop!

Use node-red-node-ping (its by node-red developers) - simply send it your array - it does the rest.

demo flow...

[
    {
        "id": "62bb480eeab3e30e",
        "type": "inject",
        "z": "68b1a8b9504a0d41",
        "name": "array of objects with host ip and name",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"name\":\"T1\",\"host\":\"10.0.0.71\",\"opis_ip_alarm\":\"ip alarm 1\"},{\"name\":\"T2\",\"host\":\"10.0.0.72\",\"opis_ip_alarm\":null}]",
        "payloadType": "json",
        "x": 1190,
        "y": 160,
        "wires": [
            [
                "4edba8054cfbc9dd"
            ]
        ]
    },
    {
        "id": "549a4d06d5505586",
        "type": "debug",
        "z": "68b1a8b9504a0d41",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1290,
        "y": 280,
        "wires": []
    },
    {
        "id": "4edba8054cfbc9dd",
        "type": "ping",
        "z": "68b1a8b9504a0d41",
        "protocol": "Automatic",
        "mode": "triggered",
        "name": "",
        "host": "",
        "timer": "20",
        "inputs": 1,
        "x": 1290,
        "y": 220,
        "wires": [
            [
                "549a4d06d5505586"
            ]
        ]
    }
]
1 Like

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