This piston returns the Public IP address that your ISP assigns to your router. This is a little tricky because although you can make a call to the ipify.org API to find your public address, this does not work exactly right using Webcore. The reason is that it will return the address of the external Webcore server instead.
In order to get “YOUR” public external IP address you will need a simple script to issue the web request to ipify.org from inside of your private network. In this example, we create this script on a Raspberry Pi.
On your Raspberry P, from a command window:
sudo apt-get update
sudo apt-get install apache2
Add the following to the end of /etc/apach2/apache2.conf
AddHandler cgi-script .py
sudo service apache2 restart
Install pip to handle python package installs:
sudo apt-get install python3-pip
Satisfy the library dependencies your about to use in your ip.py script:
pip install requests
Create a script:
sudo nano /var/www/html/ip.py
from requests import get
ip = get(‘http://api.ipify.org’).text
Make the script executable:
chmod 755 /var/www/html/ip.py
To test the script point your Web Browser to http:///ip.py
You should get back a single line that is your IP address.
To use this in a Webcore piston, you need to make a Webcore call to the local IP address of your Pi. In my example Piston, my Pi is at 172.16.1.15. You probably should statically address your Pi on your LAN.
Also notice that I am stripping off the final character at the end of the IP address in the piston. Ipify returns some non-printable character that ends up killing the “Speak Text” command in Echo Speaks.
I also create a Global variable named @PublicIP so that I can use the IP address in other pistons in my Webcore instance. So either create that Global variable or create a local one depending on your preferences.
You will also note that I use a virtual switch named ReportIP. I create an Alexa Routine that listens for “What is my Address” and then the routine turns the switch ReportIP ON. This piston makes the web call to the Raspberry Pi on the local network, which then makes a call to Ipify to get the public address. The piston then turns the virtual switch off and reports the current public IP address using Echo Speaks on which ever Echo device you select. My echo device is set to a global variable called @Echo_Location which several of my pistons use.
Here is the anonymized version if you want to import: