Luup job api and interval-timers

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:
"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/

local status, rss = luup.inet.wget(“”)

    -- 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)


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>


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)


The function name needs to be a string. Also, in the current release, the Days had to be specified even if it’s empty. I changed that in the code so the next release you won’t need the “” at the end. Try this:

luup.call_timer(“refreshCache”, 1, “30”,“”)

or for 30 minutes: luup.call_timer(“refreshCache”, 1, “30m”,“”)

ok, will try that when I get home.

btw, I wasn’t expecting the functionPtr to be a string. Most of the LUA stuff seems to use natural function references for this, so is there a implementation choice that forces this to be a string representation and/or can it be made to support both?

Mind if I add an example to your doc to illustrate it’s usage for “type 1” inputs?

I don’t think it’s possible to get it as a pointer and not a string. In the C api when doing a function call, you pass it in as a string. I’m not sure I can do it any other way. When doing Lua->Lua, of course, it’s different.

Regarding editing the wiki, of course, make any changes you want. It gives me more time to code and is very welcome.

Done, works great. I now get updates to the temp in Reno every 30 mins (I used 30 seconds to test it). Geez it’s hot there :wink:

I’ve updated your Wiki page with an example to show how to use the Interval-type Timer, using the older Syntax for now.

I don't think it's possible to get it as a pointer and not a string.

I see what you mean, they avoid passing the Lua fn ptr, or any other pointer, since it might be moved around between invocations (best I can tell, presumably due to GC etc)

Unfortunately there also doesn’t appear to be a [Function]Metatable method to get the name of the function, so it looks like Lua itself cant resolve the functions name from the functionPtr.

Oh well…

Tweaked the Wiki page a little more to indicate that the timer will only fire once, using this method, and that a further call is needed to make it fire again.