wg(ipv4.jsonip.com,json,.ip) Update Problem

Hi,

I've created a text based widget to show me info about my WiFi and network connection. It's working well except for the External IP line never updating unless I manually update it. There are five display lines:

WiFi SSID
WiFi Signal Strength in %
WiFi Speed in Mbps
Internal IP
External IP

If there's no WiFi, the first line displays •••No WiFi••• in red, and the next three lines are blank. If the cell network is connected, the fifth line continues to show my external IP (a different IP provided by my cell connection when the WiFi stopped). If there's no network at all, the fifth line displays •No Network• in red.

WiFi-Widget.jpg

I have Touch functions setup on all five lines. Touching the first line sends you to the Android WifiSettingsActivity screen. Touching any of the other four lines tells Kustom to TEXT_UPDATE.

The first four items update as and when expected. They all rely ONLY on nc() expressions. The fifth item (External IP) also relies on a wg() expression.

The code for the External IP item is:


$if(
(nc(ssid)!="" & nc(ssid)!="nossid") | (nc(cell) ="data" | nc(cell)= "dataroaming"),
("Net: " + wg(ipv4.jsonip.com,json,.ip)),
"[f=SouvMed][s=1.4][c=#FF0000]• NO Network •[/c][/s][/f]"
)$

When I go out of WiFi range (or turn WiFi off) the top line goes red, the next three lines disappear, and the fifth line stays there because I still have a network connection via cell. If I turn on airplane mode, the fifth line will change to red and show no network.

So what's the problem? The External IP address fetched by wg(ipv4.jsonip.com,json,.ip) never gets updated after the first time. When I turn off WiFi it continues to display my old WiFi IP address not my new Cell IP address. And it won't update in any amount of time. I can even open it in KWGT and edit it and it won't update. If I tap on any line on the widget once (recall that I have them set to TEXT_UPDATE when touched) the external IP always updates right away to the new IP address.

I have KWGT's update mode set to Default, and as far as I can tell KWGT is whitelisted in my Samsung S21+ properly. Everything else seems to update as expected, including the weather and time Kwidget I made last week when I discovered KWGT.

So what can I do to get "wg(ipv4.jsonip.com,json,.ip)"" to update on its own in a timely manner? And why doesn't it now? (I did read a message from Frank Monza from 5 years ago about wg() caching the json, so maybe it's hopeless, but the code I use is in the documentation as the way to get an external IP address, so I still have hope). Is there any other way for me to get my current external IP address using a different method that will update in a timely manner? As I mentioned in a previous (unanswered) question, I have my own web site that displays the external IP if I could only figure out how to tell wg() to access it, if my update problem is with json caching. I can even make a URL that just returns the calling IP address as text, if that will work.

Thanks for any help!

Billy

1 Like

I too would be interested to know if any other methods for retriving external IP addresses. :satellite:

I do remember back in the day having something similar in Symbian using python, where it parsed a site and returned the IP in text format, cached it locally, but was overwritten on a new call for it and updated no issues. The text file containing the external IP could then be parsed locally and displayed wherever you choose to have it. I wonder could CURL be implimented someway?

Would be cool if there was someway to have it update like the nc expression, which will just return a blank if no network or an instant change on a network swap
Will keep an eye :eye: open anyway (the one I can still just about use after the weekend playing with KWCH :eyeglasses: :laughing: )

Quick question, for any that know. I’m assumingwg(ipv4.jsonip.com,json,.ip) will grab just the ip4v IP and wg(jsonip.com,json,.ip) will grab whatever is there, ipv4 or ipv6? Reason for asking is either way I get both, but is there a way to specify just IPv4 result?

Cheers for the bit of kode as well Billy :+1:t3: , will be using some of it, saved me a few hours of trial and error :rofl: