Hello,
I am trying to make a flow that will email me when my IP changes on a pi I have at another property.
I am using the nodered-contrib-IP object.
My default IP gets added to lastIp but it never gets updated via the flow.set function and the "My current IP" gets returned every time.
Function:
var lastIp = flow.get('lastIp')||'192.168.1.0';
var currentIp = msg.payload.publicIPv4;
node.warn(lastIp);
if (lastIp === currentIp) {
msg.payload = "same IP" + lastIp;
return msg;
}
else if (lastIp != currentIp) {
msg.payload = "My current IP is "+currentIp;
flow.set('lastIp', lastIp);
return msg;
}
Here is the flow:
[{"id":"3c107d5a.937752","type":"ip","z":"43e22b7d.f2cf34","name":"ip","https":false,"timeout":"5000","internalIPv4":true,"internalIPv6":false,"publicIPv4":true,"publicIPv6":false,"x":490,"y":560,"wires":[["7b66da7f.387524"]]},{"id":"db2b1954.738d78","type":"debug","z":"43e22b7d.f2cf34","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":830,"y":560,"wires":[]},{"id":"b359d53e.74d828","type":"inject","z":"43e22b7d.f2cf34","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":560,"wires":[["3c107d5a.937752"]]},{"id":"7b66da7f.387524","type":"function","z":"43e22b7d.f2cf34","name":"Compare IP","func":"//context.lastip = context.lastip || 'initial';\nvar lastIp = flow.get('lastIp')||'192.168.1.0';\nvar currentIp = msg.payload.publicIPv4;\nnode.warn(lastIp);\n//node.warn(\"help\"+currentIp);\nif (lastIp === currentIp) {\n msg.payload = \"same IP\" + lastIp;\n return msg;\n//context.get = currentIp;\n//msg.payload = \"same \"+currentip;\n}\nelse if (lastIp != currentIp) {\n msg.payload = \"My current IP is \"+currentIp;\nflow.set('lastIp', lastIp);\nreturn msg;\n}","outputs":1,"noerr":0,"x":650,"y":560,"wires":[["db2b1954.738d78"]]}]
Thanks for any input for this rookie!
Cheers,
Jon