I'm using a node that returns (2) msg.payload see image, how do I address each msg.payload within a "Function" node?
How are you making the PING?
There seems a lot you aren't showing, so the question is not really answerable as given.
The usual way to distinguish them would be by msg.topic, which in your case seems to be "1.1.1.1" or "8.8.8.8"
So in your function node you can have
if (msg.topic === "1.1.1.1") {
blah
}
else if (msg.topic === "8.8.8.8") {
blah
}
else {
blah
}
You can also pass the messages through a join node in "Manual" mode (since they have different topics) which would result in a single message with properties msg.payload["1.1.1.1"] and msg.payload["8.8.8.8"]
If you do this and have control of the topic, it would be better to use a string which does not begin with a digit - "cloudflare" and "google" spring to mind
That allows simpler notation msg.payload.cloudflare etc.
This might be a better bet: Ping Network Devices From a List - #12 by Steve-Mcl
I have an array of 3 [0,1,2) and my msg.payload is showing the objects correctly msg.payload[0], msg.payload[1], msg.payload[2].
So here is my problem I can't figure out.
I'm checking to see if all three are TRUE (Boolean) if they are how to I make (add) another array? msg.payload[3].
Example ; If (msg.payload[0] != false && msg.payload[1] != false && msg.payload[2] != false) {msg.payload[3] === true} **This would be the array I need added**
This is a comparison not an assignment.
But the right way to add an element to an array is array.push()
if (msg.payload[0] != false && msg.payload[1] != false && msg.payload[2] != false) {
msg.payload.push (true)
}
Thanks for catching my error! I will try the array.push()
You can also use
if (! msg.payload.includes (false)) {
msg.payload.push(true)
}
Thank you so much, it is working as I hoped. And thanks for the tips.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.