Are you stuck in a situation where your WAN IP changes faster than nappies on a year old baby, ruining the access to your network connected drives and other services? Running a premium DNS service with the automatic IP updates can be expensive so it’s time to revisits other options.
Automatic IP updater
Fortunately, you have some options. Not all of them are perfect, but the one I’m going to talk about in this article is free.
- Use a premium DNS (or free with limitations) service
- Check this Python script out
- carrying on reading for NodeRED implementation
How does it work?
The NodeRED flow checks every couple of minutes what is the current IP and if the IP has changed, issues the notification to the relevant device. Using the API I found on the internet, you will be able to send the current WAN IP to any AutoRemote compatible device (Android, Windows PC). The free allowance of 1000 calls a day makes possible to monitor the IP changes every 2 min without additional payments. BONUS: no account creation required to use the API.
NodeRED Flow: Current IP
The “Insert” node comes with repeat setting, which I can use to query the API every X minutes. You could set this to trigger as often as 2 min without hitting the 1000/day limit. I think there is very little reason for the excessive calls so 5-10 min interval is more than enough.
To make the API call, I’m simply making HTTP GET request to:
http://api.db-ip.com/v2/free/self/ipAddress
The response is your IP address which is saved as a global variable with global.set("CurrentIP", msg.payload)
. I want to set this value only if the device was online, so checking if the msg.statusCode === 200
is a good idea to see if the request has been sent correctly.
I don’t want to spam this message back to my AutoRemote devices unless the value changes, so I placed the RBE node that passes the value when the value changes.
Sending AutoRemote
I send a lot of information via AutoRemote so it makes sense to automate the process somehow. I created a subflow that requires the following information to make the successful request:
- msg.message – message to pass
- msg.timeout – TTL
- msg.device – device name
The message sent to the device contains the prefix currentip
and the command with xxx.xxx.xxx.xxx IP: currentip=:=xxx.xxx.xxx.xxx
this way I can easily use it in Tasker to set the new IP as a variable
Subflow
AutoRemote is essentially making a request via Gooogle API to the registered mobile device or a computer running EventGhost. You will need an AR key associated with your device. I’m my example I used the credentials system I designed for NodeRED. The values are stored as global variables and can be pulled by setting the correct device.
//set up AR response var device = "AR_"+ msg.device; var message = msg.message; var timeout = msg.timeout; var key = global.get(device); //send AR response if(timeout === null || timeout === undefined){ timeout = 10; } if(message === null || message === undefined){ message = "no message set"; } var url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=" + key + "&message=" + message + "&ttl="+ timeout; msg.url = url; msg.feedback = "Messgage send to " + device + ": " + message; return msg;
That script is passed to the HTTP POST and executed. I have added a msg.feedback in output in case you ever want to see what message has been sent. You can reuse this subflow in every flow that requires the AR message to be submitted.
Using the new IP in Tasker and EventGhost
Now, that the IP has been updated and sent to the preferred devices, I will show you how to update the designated variable with the new value. I will use Tasker to do this on Android and EventGhost to store the IP as a variable in EventGhost.
Tasker: My IP
The profile will respond to an intercepted message currentip
and update the variable of your choice %CURRENTIP (click here to learn why I use upper case for these).
The Tasker’s profile is supers simple and once your variable is updated you can use it to send HTTP request back to your home server.
EventGhost: My IP
In a similar manner, the intercepted message by EventGhost can be set as a variable in the EventGhost itself. You will be able to pass this data in your scripts to execute other commands and send the web requests.
This is how to extract the IP from the message and save it as a variable:
IP = eg.event.payload.arcomm setattr(eg.globals, "CurrentIP", IP) print IP
And this is how you recall the global variable and use it in a python script.
IP = getattr(eg.globals, "CurrentIP") print IP
Conclusion
Even if your IP changes frequently, you can keep track of that with this project and make sure your systems always have the up to date data. The best part of it – it’s free! Let me know how often your IP changes! If you want to learn more about Tasker use this portal, alternatively I have a very good 7 part tutorial to teach you more about NodeRED. Does your ISP come with serious rules about IP assignment and lease times? Use this Reddit thread to leave me a message.
Project Download
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.