based on the fact that 4.icfg.me seems to be no longer working and thans to dzVents new frameworks that support Http response,
I rewrite the wan IP checker that now looks much smarter:
Code: Select all
local getIp = 'https://api.ipify.org/?format=json'
return {
on = {
timer = { 'every 6 hours' },
httpResponses = { 'wanIP' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = '[WAN IP]'
},
execute = function(dz, devNil)
local actIP = dz.devices('Wan IP').text
local newIP = 'Unable to retrieve IP'
if (devNil.isTimer) then
dz.log("Send WanIP request")
dz.openURL({
url = getIp,
method = 'GET',
callback = 'wanIP'
})
elseif (devNil.isHTTPResponse) then
dz.log("WanIP response")
if (devNil.ok) then -- statusCode == 2xx
newIP = devNil.json.ip
end
if newIP ~= actIP then
dz.devices('Wan IP').updateText(newIP)
end
end
end
}