Log Error : luup_variable_get interface 0xb1ede8 no CurrentTemperture/ (null)

Hi

Just when you think you know what you’re doing when coding, something you thought simple is not working. The following code run via the Lua test window, claim to be successfull but…

local benTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 210) local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"

Returns the following error in the logs and the rest of the code does not seem to work…

01 03/07/14 23:57:14.184 luup_variable_get interface 0xb1ede8 no CurrentTemperature/(null) <0x2f908680>

The device number is correct and I can see a value in the CurrentTemperature variable.

As an FYI the full code I’m looking to use is as follows, above is the isolated error I get.

[code]local benTemp = luup.variable_get(TEMP_SID,“CurrentTemperature”, 210)
local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1”

luup.inet.wget(“http://www.prowlapp.com/publicapi/add?apikey=Xxxxxxxxxxxxxxxxxxxxxxxxxxxx&application=Vera+Temperature+Notification&event=Alert&description=Ben’s+Room+Is+At+%s+degrees&priority=1”, benTemp)
end[/code]

Don’t you need to set the TEMP_SID before you use it?

local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1”
local benTemp = luup.variable_get(TEMP_SID,“CurrentTemperature”, 210)

Thanks @Bulldoglowell

Yep, it’s so obvious now you mentioned it… Thanks again…

The rest of the code above is not quite right as it does not place the benTemp variable vale into the text. Any ideas on that?

luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=Xxxxxxxxxxxxxxxxxxxxxxxxxxxx&application=Vera+Temperature+Notification&event=Alert&description=Ben's+Room+Is+At+" .. benTemp .. "+degrees&priority=1")

Did I mention that there are easier ways to debug Lua?

the “RexBeckett debug kit” tells you the answer… that’s a big advantage!

No license fee required but the response time can be somewhat variable. ;D

Thanks Rex

Your really are a walking-coding machine :slight_smile:

You did, however I often find myself working on my iPad 90% of the time - so I kinda have to bounce between the lua test page on Vera (why there is not another way to submit code via the browser) and the log file viewer.

Not ideal but the lua iOS apps I’ve used have never been any good at helping me to debug especially when they contain luup.

You did, however I often find myself working on my iPad 90% of the time - so I kinda have to bounce between the lua test page on Vera (why there is not another way to submit code via the browser) and the log file viewer.
Vera has some guard-rails in place to limit what can be done through an http handler. However...

Can you edit files on Vera using your iPad? I think I read that Textastic could do that? Otherwise can you ftp files to Vera? If so, here’s a trick you might like.

Create a Vera scene (a good name would be LuaTest) and paste the following code into the LUUP tab:

local testf = "/etc/cmh-ludl/luatest.lua" luup.log("LuaTest File: " .. testf) f, err = loadfile(testf) if f ~= nil then local res, msg = pcall(f) if res then luup.log("LuaTest Code returned: " .. tostring(msg)) else luup.log("LuaTest Error: " .. (msg or "nil")) end else luup.log("LuaTest Error: " .. err) end

Place the code to be tested in Vera file /etc/cmh-ludl/luatest.lua

Execute your TestLua scene with this browser command (change SceneNum to suit):

<veraip>:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&output_format=json&SceneNum=93

See the results in LuaUPnP.log.

The debug process is:

[ol][li]Edit code directly on Vera or ftp new version[/li]
[li]Run the LuaTest scene[/li]
[li]Check the log[/li]
[li]Repeat 1-3 until bugs == 0[/li][/ol]

Hi Rex

If you’ve not heard it for a while. You’re great :slight_smile:

That looks like a great idea, and I actually already have TextTastic.

However I could never get it to connect to Vera, I think that’s because Vera needs SCP and Texttastic can only do FTP or SFTP.?

I found this from a while back → http://forum.micasaverde.com/index.php/topic,11466.0.html

I don’t know much about what Apps are available for iOS but I would be astonished if there isn’t some way to edit or ftp a file to Vera. I’ve always been told that there is an iOS App for everything… Perhaps there is an iWizard on the forum who can help here.

I know it’s amazing to think they do not have an app that allows you to transfer files using SCP. I just looked again and it seems still no one has released something that would do it. I even recall contacting the Textastic owner early last year to see if they would add it, but they didn’t think there was any need.

I did install CIFS support for the external NAS support so maybe there is an option there.

I have a mapped drive on my Vera called ‘nas’, let me see if that allows me to do something…

Perhaps I shouldn’t mention it but…

Having not tried this with my Android tablets, I wondered how easy it would be. Less than two minutes later, I had installed AndFTPPro, connected to Vera, downloaded my test lua file and opened it in a text editor.

Tell me again why you like your iPad so much? :wink:

I guess I’m just a sucker for the look and feel of a Granny Smith :slight_smile:

::slight_smile:

I may not be able to fix your iPad/Vera communication issues, Chris, but here’s LuaTest with added http…

The following code can be placed in Startup Lua for permanent availability or just run once in Test Luup (Lua) for temporary use (until the next restart).

[code]function rbLuaTestRun(luafile)
luup.log("LuaTest File: " … luafile)
rbLuaCode, rbLuaErr = loadfile(luafile)
if rbLuaCode ~= nil then
local res, msg = pcall(rbLuaCode)
local retstr
if res then
retstr = "Code returned: "
else
retstr = "Runtime error: "
end
retstr = retstr … tostring(msg)
luup.log("LuaTest " … retstr)
return retstr
else
luup.log("LuaTest Code error: " … rbLuaErr)
return "Code error: " … rbLuaErr
end
end

function rbLuaTest (lul_request, lul_parameters, lul_outputformat)
local testfile = lul_parameters[“file”] or “/etc/cmh-ludl/luatest.lua”
local html = “\n” …
“LuaTest\n” …
“\n” …
“\n” …
“LuaTest
\n”
local result = “”
html = html … "Lua file: " … testfile … “
\n”
rbLuaRun = coroutine.create(rbLuaTestRun)
local status, retn = coroutine.resume(rbLuaRun,testfile)
html = html … retn … “
\n”
local content_type = “text/html”
return html, content_type
end

luup.register_handler(“rbLuaTest”,“LuaTest”)
[/code]

To run your test file, enter the following in a browser:

<veraip>:3480/data_request?id=lr_LuaTest&file=XXXX

Replace XXXX with the pathname of the file to be tested. If you do not specify a file name, the default is /etc/cmh-ludl/luatest.lua

The browser will show the value returned by your code or an error message. Diagnostic messages are also written to LuaUPnP.log.

Have fun. ;D

Wow, thanks Rex, this looks like it’ll be fun to use…

OK, now the next job is to get the luatest.lua file from my NAS to Vera.

Now the share that file is in, is already mapped to Vera under the name nas, it sounds like the best place to copy it to is /etc/cmh-ludl/luatest.lua.

I’m trying to find some lua code that will handle that task. Is fs.copy the way to go?

fs.copy ("/nas/luatest.lua" , "/etc/cmh-ludl/luatest.lua")

LuaInterface::StartEngine failed run: 0 [string “fs.copy (”/nas/luatest.lua" , “/etc/cmh-lud…”]:1: attempt to index global ‘fs’ (a nil value) <0x3023c680>
JobHandler_LuaUPnP::RunLua failed: fs.copy (“/nas/luatest.lua” , “/etc/cmh-ludl/luatest.lua”) <0x3023c680>

Is there a http request that could do this copy action too? That way I could have two URLs to use, one to copy and the one to execute the file.

If your NAS is mapped into Vera’s file system, try:

<veraip>:3480/data_request?id=lr_LuaTest&file=/nas/luatest.lua

Wow-o-wow…

Finally got to test out your code today (via the test Luup (Lua) and then clicked on the URL to run the file from the /nas/ and it worked wonderfully !!

Results are…

LuaTest
Lua file: /nas/luatest.lua
Code returned: nil

As it worked I assume ‘nil’ is a good thing?

This is great, it makes it so simple to do.

Out of interest is there anything else that can be returned on the results page?

Can it show a copy of the code I’m running ?
Can it provide a URL to the log file, so I click one to execute and then can click another to see the log?
Can it provide any other information that might be useful ?

Finally got to test out your code today (via the test Luup (Lua) and then clicked on the URL to run the file from the /nas/ and it worked wonderfully !!
I'm pleased to hear it.
Code returned: nil As it worked I assume 'nil' is a good thing?
I included this because it is important for Lua used in scenes. It shows the value that your code returned with the [b]return [/b] statement. If you don't provide a value, or don't explicitly return, the result will be nil. It is [i]good[/i] in the sense that it could have been an error message instead. ;)
Can it show a copy of the code I'm running ?
It perhaps could but why would that be better than looking at it in your still-open text editor where you can also fix the bugs?
Can it provide a URL to the log file, so I click one to execute and then can click another to see the log?
Doesn't your browser have tabs?
Can it provide any other information that might be useful ?
I'm thinking of showing [i]stdout[/i] so that you could use [b]print[/b] statements to assist with debug.

Thanks For the quick response Rex

Seriously this is really good, especially with a CIFS mapped drive as it gets over the SCP issue and I can have any number of testluaxx.lua files now each with their own URL.

As an iPad use it also helps to deal with the browser caching issue with Safari. (Well I assume that"s what’s occurring when you cannot reload the UI in the browser as it just hangs) i often have to bounce over to Chrome to start doing things via the UI again.

[b]Re: link to the logs[/b] - Good point about the browser tabs. :) Suggesting the URL was just as a reminder if you wanted to see the results in the logs (or if you forgot to run it in advance)
[b]Re: showing the code that's been run[/b] - The idea here was again just as a validation step, to be sure the new code was being processed, incase it was not being updated. Plus sometime's seeing the same info in a different way could make things you missed stand out

What does stdout mean ?

I assume by Print, that would work as a form of logging ?