Skip to content

Instantly share code, notes, and snippets.

@jhottell
Last active November 29, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhottell/2d534ee501c9ad89ac37 to your computer and use it in GitHub Desktop.
Save jhottell/2d534ee501c9ad89ac37 to your computer and use it in GitHub Desktop.
Send IP Address of Node-Red on power up or deploy

Email IP address on boot. Windows and Linux / Raspberry Pi examples.

[{"id":"f4a7bf68.4bb2f","type":"exec","z":"ae01984f.e3b838","command":"ipconfig","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"ipconfig","x":254.00000381469727,"y":75.0000057220459,"wires":[["a3770ba3.f0df88"],[],[]]},{"id":"4938ce95.aae0e","type":"inject","z":"ae01984f.e3b838","name":"","topic":"ip","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"x":109.00000762939453,"y":74.50000762939453,"wires":[["f4a7bf68.4bb2f"]]},{"id":"a3770ba3.f0df88","type":"function","z":"ae01984f.e3b838","name":"Extract network config","func":"var input, tokens, IP;\nvar outString = \"Node-Red IP Address\\n\";\n\ninput = msg.payload;\ntokens = input.split(\"IPv4\", 5);\ntokens = tokens[1].split(\":\", 5);\ntokens = tokens[1].split(\" \", 5);\nIP = tokens[0].trim();\n\noutString = outString + IP;\n\nreturn {payload: outString};\n\n\n\n\n","outputs":"1","noerr":0,"x":178.00006484985352,"y":152.0000228881836,"wires":[["ddbc079.5f992f8"]]},{"id":"4659e651.7f6f48","type":"debug","z":"ae01984f.e3b838","name":"","active":true,"console":"false","complete":"false","x":353.70001220703125,"y":180.0000171661377,"wires":[]},{"id":"1b57a8f0.b87867","type":"exec","z":"ae01984f.e3b838","command":"ifconfig","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"ifconfig","x":274.0000228881836,"y":364.0000219345093,"wires":[["e26dcada.afaed8"],[],[]]},{"id":"251aa90f.663af6","type":"inject","z":"ae01984f.e3b838","name":"get ip - eth0","topic":"Node-Red IP Address","payload":"eth0","payloadType":"str","repeat":"","crontab":"","once":true,"x":122.0000228881836,"y":363.5000219345093,"wires":[["1b57a8f0.b87867"]]},{"id":"6c853446.2fa74c","type":"debug","z":"ae01984f.e3b838","name":"test out","active":true,"console":"false","complete":"payload","x":331.0000228881836,"y":490.5000219345093,"wires":[]},{"id":"e26dcada.afaed8","type":"function","z":"ae01984f.e3b838","name":"Extract network config","func":"// Initialize variables\nvar input, tokens, inet, bcast, mask;\nvar outString = \"TestRasPi network config for eth0\\n\";\n\n// Parse the entire string by spaces, and put each item into an array called tokens\n\ninput = msg.payload;\ntokens = input.split(\":\", 10);\n\n// Get the 7th token (example: \"addr:192.168.0.120\")\n// and get the substring from character 6 to the end\ninet = tokens[7].split(\" \", 1);\noutString += \"\\n\" + \"inet addr: \" + inet[0];\n\n// Get the 8th token (example: \"Bcast:192.168.0.255\")\n// and get the substring from character 7 to the end\nbcast = tokens[8].split(\" \", 1);\noutString += \"\\n\" + \"Bcast: \" + bcast[0];\n\n// Get the 9th token (example: \"Mask:255.255.255.0\")\n// and get the substring from character 6 to the end\nmask = tokens[9].split(\" \", 1);\noutString += \"\\n\" + \"Mask: \" + mask[0];\n\n// Don't send a message if the IF is the known default. Change to default ip.\nif (inet==\"192.168.0.120\") { \n//outString = \"\"; // set output to null if ip is the same so no message is sent\nreturn null;\n}else{\n// return the final output\nreturn {payload: outString};\n}\n","outputs":1,"noerr":0,"x":170.00003814697266,"y":439.0000333786011,"wires":[["65917828.802778"]]},{"id":"65917828.802778","type":"delay","z":"ae01984f.e3b838","name":"Delay","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":157.0000228881836,"y":503.0000219345093,"wires":[["6c853446.2fa74c","f34d4d20.05c8"]]},{"id":"f34d4d20.05c8","type":"e-mail","z":"ae01984f.e3b838","server":"smtp.gmail.com","port":"465","secure":false,"name":"someemail@msn.com","dname":"Email out","x":338.0000228881836,"y":532.5000219345093,"wires":[]},{"id":"ddbc079.5f992f8","type":"delay","z":"ae01984f.e3b838","name":"Delay","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":171.00005722045898,"y":208.000018119812,"wires":[["897f8590.8e7118","4659e651.7f6f48"]]},{"id":"897f8590.8e7118","type":"e-mail","z":"ae01984f.e3b838","server":"smtp-mail.outlook.com","port":"587","secure":false,"name":"someone@msn.com","dname":"Email Out","x":349.0000686645508,"y":229.00000858306885,"wires":[]},{"id":"765f2cd3.1bb164","type":"comment","z":"ae01984f.e3b838","name":"Windows example","info":"","x":138.6999969482422,"y":25,"wires":[]},{"id":"de08137b.6b5ad","type":"comment","z":"ae01984f.e3b838","name":"Raspberry / Linux Example","info":"","x":140,"y":321.00000762939453,"wires":[]}]
@imv7
Copy link

imv7 commented Nov 29, 2017

image
image

What is the exec module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment