Tweet Ip address upon bootup

This flow is fairly simple and does exactly what the title says, it tweets your Ip address once your raspberry pi (or whatever linux system you are using) has powered up and has node red running. It also runs a check to see if your IP address is the default IP address that your system normally uses (you must set this in the function!) as to avoid tweeting when you already know where it is. This flow is extremely useful when taking your node-red system to a friend's house or presentation and you need to find it on the network.

#

The tweet will be in the form ...(not compressed here because of available formatting)...

TestRasPi network config for eth0 (Preliminary message, user settable)

inet addr: 192.168.0.120

Bcast: 192.168.0.255

Mask: 255.255.255.0

(Ok, fine, I lied. It doesn't just print out your IP, but just look at all that useful info!)

#

Usage:

Step 1. Copy flow into node-red

Step 2. Update twitter credentials with the account you want your IP to be tweeted on

Step 3. Open up the function node and change "DefaultIP" to your default, known IP address

Step 4. Enjoy always knowing where your system is on the network!

#

Note: This will only work on linux installations, specifically tested using debian on the raspberry pi.

[{"id":"fdf4c19d.020b4","type":"exec","command":"ifconfig","append":"","useSpawn":false,"name":"ifconfig","x":250,"y":120,"z":"4e9fa0fb.b1606","wires":[["a9026acc.56fd98","9ac15a53.653ea8"],[],[]]},{"id":"fb5f1434.04a0e8","type":"twitter out","twitter":"","name":"Tweet ip","x":810,"y":120,"z":"4e9fa0fb.b1606","wires":[]},{"id":"8cc3ead1.733c18","type":"inject","name":"get ip - eth0","topic":"ip","payload":"eth0","payloadType":"none","repeat":"","crontab":"","once":true,"x":97,"y":120.5,"z":"4e9fa0fb.b1606","wires":[["fdf4c19d.020b4"]]},{"id":"a9026acc.56fd98","type":"debug","name":"","active":false,"console":false,"complete":false,"x":399,"y":66.5,"z":"4e9fa0fb.b1606","wires":[]},{"id":"d580cc31.2a7f3","type":"debug","name":"test out","active":true,"console":"false","complete":"false","x":628,"y":65.5,"z":"4e9fa0fb.b1606","wires":[]},{"id":"9ac15a53.653ea8","type":"function","name":"Extract network config","func":"// This node parses the info from the command \"ifconfig\" \n// and outputs a string such as:\n\n//\"TestRasPi network config for eth0 \n//inet addr: 192.168.0.120 \n//Bcast: 192.168.0.255 \n//Mask: 255.255.255.0\"\n\n// This parsed info can then be passed to whatever service you want it to be sent out on. My favorite is twitter.\n// Function created by Teslafly - Feel free to do anything you want with it.\n\n// user variables\nvar DefaultIP = \"192.168.0.100\"; // Change to whatever ip adress you dont want your system to tweet on.\n\n\n\n// beginning of function\n/////////////////////////////////////////////////////////\n// Initialize variables\nvar input, tokens, inet, bcast, mask;\nvar outString = \"TestRasPi network config for eth0\\n\"; // start message of outstring, change if you want the beginning of your message to be different.\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==DefaultIP) { \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,"x":450,"y":120,"z":"4e9fa0fb.b1606","wires":[["d580cc31.2a7f3","1b91eb52.e46e15"]]},{"id":"1b91eb52.e46e15","type":"delay","name":"let init","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":650,"y":120,"z":"4e9fa0fb.b1606","wires":[["fb5f1434.04a0e8"]]}]
Teslafly

Flow Info

created 3 years, 11 months ago

Node Types

Core
  • debug (x2)
  • delay (x1)
  • exec (x1)
  • function (x1)
  • inject (x1)
  • twitter out (x1)

Tags

  • twitter
  • IP_address
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option