OH3.0 HTTP binding migration to get WAN IP

In OH 2.x I used the http binding to get the WAN IP of my system. I have a text-only configuration, so
the configuration files for the http binding in OH3.0 had to be changed.
There are other approaches to get the WAN IP address which use rules or scripting.
This approach is build on a Things definition with a REGEX transformation in the channel definition.

This is my solution:

OH2.x http.cfg file (just fyi, http.cfg is obsolete in OH3)


OH2.x items (just fyi)

String Network_WAN_IP "WAN IP address [%s]"  {http="<[WANIP:60000:REGEX((.*?))]"} 

OH3 Things definition

Thing http:url:wan_ip "Wan IP Adress" [ baseURL="https://api.ipify.org", refresh=86400 ] {
        Type string : address   "WANIP" [ stateTransformation="REGEX:(.*?)" ]


OH3 Items definition

String Network_WAN_IP "WAN IP address [%s]"  {channel="http:url:wan_ip:address"} 

Finding the correct things configuration was kind of try&error. It helped me a lot to set the trace level for the HTTP binding to TRACE.


Thank You, this helped me after I transitioned to OH3 -hasn’t worked for nearly a year now and after this it worked with no issues.