I’m trying to use an interval Timer to refresh a cache, but can’t seem to get it working. Specifically I’m using [tt]luup.call_timer[/tt], and it’s old-style parameter doc from:
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions
"For an interval timer, days is not used, and Time should be a number of seconds, minutes, or hours using an optional 'h' or 'm' suffix"
Given the description above, my assumption was that I could use [tt]luup.call_timer[/tt] with only three parameters, as in the following code:
function startup(lul_device)
luup.log("Yahoo! Weather #" .. tostring(lul_device) .. " starting up with id " .. luup.devices[lul_device].id)
refreshCache()
luup.call_timer(refreshCache, 1, "30")
end
where the refreshCache function looks like:
[code] function refreshCache(garbage)
–
– And some test code that call’s Yahoo’s Weather API/URL/
– http://developer.yahoo.com/weather/
–
local status, rss = luup.inet.wget(“http://weather.yahooapis.com/forecastrss?p=89502”)
--
-- For demo, print a set of values showing them individually pulled out.
--
luup.log(string.format("In %s, it\'s currently %s(%s) and %s. Humidity is %s",
extractElement(rss, "yweather:location")["attrs"]["city"],
extractElement(rss, "yweather:condition")["attrs"]["temp"],
extractElement(rss, "yweather:units")["attrs"]["temperature"],
extractElement(rss, "yweather:condition")["attrs"]["text"],
extractElement(rss, "yweather:atmosphere")["attrs"]["humidity"]))
luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature",
extractElement(rss, "yweather:condition")["attrs"]["temp"], lul_device)
luup.variable_set("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel",
extractElement(rss, "yweather:atmosphere")["attrs"]["humidity"], lul_device)
end
[/code]
But when I do this, the timer never fires, instead I get the following in the logs (the first line is my explicit call of [tt]refreshCache()[/tt] in my startup, not the timer):
50 07/27/09 11:30:58.903 luup_log:484: In Reno, it's currently 89(F) and Partly Cloudy. Humidity is 16 <0x803>
...
01 07/27/09 11:30:59.071 luup_call_timer interface 0x898d88 args 3 <0x803>
Given this error, I’m guessing that I need to provide all 5 parameters, but when I tried putting in “garbage” strings into the 4th and 5th, I get:
01 07/27/09 11:28:15.760 luup_call_timer can't find parms <0x803>
Thoughts?
Also, can we make the job-types into Constants? I’d rather not pass “1” as the parameter value. I also tried passing 30 (no quotes, number) as the time in seconds, but couldn’t tell if it would take that or not (since it can take “20m”, an “2h” per doc)
r807