Search code examples
jsonnode-red

create a ping with true or false response in json


I am using node red "node-red-node-ping" to ping 192.168.0.71. The response looks like this

192.168.0.71 : msg : Object
object
payload: 0.376
topic: "192.168.0.71"
_msgid: "f766d646.764dc8"

if the ip address is not ping-able, payload is "false", and if found the payload returns trip time in ms. (0.376)

I need to use the function node (json) to change the trip time numeric response to "true" and keep the false response if the ip was not found


Solution

  • Sounds like you want to branch based on whether the node is "pingable", which is what a switch node does. Add a rule to check if msg.payload > 0 (the number), and send the msg to port #1. Add another rule set to "otherwise" which sends the other "false" msgs to port #2. Then wire port #1 to a change node which sets msg.payload to the value "true".