you pass the device here…
function initialize (lul_device)
but yet you’ve hard coded the device into your function here:
local existingIP = luup.variable_get("urn:nodecentral-com:serviceId:ExternalIP1","ExternalIP", 376)
local oldIP = luup.variable_get("urn:nodecentral-com:serviceId:ExternalIP1","OldIP", 376)
try:
local existingIP = luup.variable_get("urn:nodecentral-com:serviceId:ExternalIP1","ExternalIP", lul_device)
why do you log non-events?
if (newIP == existingIP)
then luup.log("External IP has not changed, so nothing to do")
print("External IP has not changed, so nothing to do")
just look for the state change and act/log accordingly.
did you know that luup.variable.get actually returns two values?
local existingIP, lastUpdateTime = luup.variable_get("urn:nodecentral-com:serviceId:ExternalIP1","ExternalIP", 376)
you can use that, and you wouldn’t need the other variable:
luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "LastUpdate", os.time(), 376)
because you already have it!
make it easier on yourself during debug:
luup.log("External IP has changed, so update made")
function logToVera(mssg)
luup.log("MyPluginName: "..mssg)
end
logToVera("External IP has changed, so update made")
and
tail -f LuaUPnP.log | grep MyPluginName:
props to @akbooer for teaching me some of this!
EDIT:
if (newIP == existingIP)
then the only alternative is they don’t match! So:
if (newIP == existingIP) then
luup.log("External IP has not changed, so nothing to do")
print("External IP has not changed, so nothing to do")
else
-- the other thing
end
and look to beautify your code for proper indentation:
[code]
function initialize (lul_device)
local status, ip = luup.inet.wget(“http://checkip.dyndns.org”)
local newIP = ip: match “%d+%.%d+%.%d+%.%d+”
local existingIP = luup.variable_get(“urn:nodecentral-com:serviceId:ExternalIP1”,“ExternalIP”, 376)
local oldIP = luup.variable_get(“urn:nodecentral-com:serviceId:ExternalIP1”,“OldIP”, 376)
print(“My new IP is : '”…newIP…“'”)
luup.log(“My new IP is : '”…newIP…“'”)
print(“My existing IP is : '”…existingIP…“'”)
luup.log(“My existing IP is : '”…existingIP…“'”)
print(“My old IP is : '”…oldIP…“'”)
luup.log(“My old IP was : '”…oldIP…“'”)
–[[
if (oldIP == nil or ‘’) then
luup.variable_set(“urn:nodecentral-com:serviceId:ExternalIP1”,“OldIP”, “000.000.000.000”, 376)
luup.log(“No previous IP is present so adding a temporary one”)
print (“No previous IP is present so adding a temporary one”)
–]]
if (newIP == existingIP)
then luup.log(“External IP has not changed, so nothing to do”)
print(“External IP has not changed, so nothing to do”)
else
luup.log(“External IP has changed”)
print(“External IP has changed”)
luup.variable_set(“urn:nodecentral-com:serviceId:ExternalIP1”,“OldIP”, oldIP, 376)
luup.variable_set(“urn:nodecentral-com:serviceId:ExternalIP1”,“ExternalIP”, newIP, 376)
luup.variable_set(“urn:micasaverde-com:serviceId:HaDevice1”, “LastUpdate”, os.time(), 376)
– print(“Update made : '”…oldIP…“'”)
– luup.log(“Update made : '”…oldIP…“'”)
print(“External IP has changed, so update made”)
luup.log(“External IP has changed, so update made”)
–end
end
end
end[/code]
note how to comment a block of code…
--[[
comments here
and here
are ignored
--]]