Testing Code - For A Newbie

How best do I test code ?

I’m in the very early stages of learning to write code for my Vera (and I’ve never-ever coded before), by any chance is there an online place with virtual devices which could step me through each line of my code? (A form of debugging, with step by step results I guess)

For example I’ve been trying to write my first few bits of code, which I’m trying to test via the Apps/Develop on UI5 - After initially getting some errors, I’ve successfully sent a couple now which the UI tells me the ‘message sent’ was OK, but nothing seems to happen?

For example - Is there a way I can see on the screen the answer to the following luup.variable_get request, so I know I got it right?

[code]-- Picking the devices
local SENSORID= 42 – The sensor device ID number

– Picking the services
local SENSERV = “urn:micasaverde-com:serviceId:HaDevice1”

luup.variable_get(SENSERV, “BatteryDate”, SENSORID)
[/code]

All that ever worked for me is tailing the Luup log (/var/log/cmh/LuaUPnP.log) while running code that contains luup.log(…) statements. It’s awfully low-tech and a complete pain for logging Lua tables and other data structures.

Thanks futile, I maybe very new to all this, but it seems a shame that there is not a debugging interface for code. It would certainly help a newbie out :wink:

Regarding monitoring the Luup log file, is everything logged to that or do you have to add a line of code to make it write to that log file?

If your code executes luup.log(“foo”) then the logfile will contain a line with “foo” in it.

Other stuff gets logged too, but if you want to be sure, use luup.log().

Thanks futzle

So using the example piece of code i pasted in above, where would I put the luup.log() entrry so I can check the results? Will it also show any explain any errors etc.

Would it be possible to create a device on the UI that’s simply a window to that log file? I work a lot on the iPad (using the Textastic app) so to access any log files requires the use of WinSCP on a PC?

It seems strange that MCV wants to encourage developers to help build out their App Store, yet they seem to make any testing/debugging a rather cumbersome experience?

local v = luup.variable_get(…)
luup.log("v is " … v)

It’s really only glorified print statements.

No plugin exists to give you UI access to the log. It’s far too verbose for that anyway. I’m afraid that this is one of those things that you’ll have to put down the iPad for and use a Real Computer.

To see the log in a browser: http:///cgi-bin/cmh/log.sh?Device=LuaUPnP

Also, you could SSH into Vera from your iPad and look at the log.

(You may or may not want to turn on verbose logging and/or manipulate log levels directly in /etc/cmh/cmh.conf; and probably set [tt]ImmediatelyFlushLog[/tt] to 1, if not already done.)

Hi futzle

Thanks I assume I add it to the top, please see the results below. My expectation is that it would return the BatteryDate/Time.

[quote=“futzle, post:6, topic:172947”]local v = luup.variable_get(…)
luup.log("v is " … v)

It’s really only glorified print statements.[/quote]

This was in the log (thanks OTI@ for the URL that’s a great bit of information)

08	10/10/12 19:58:11.860	JobHandler_LuaUPnP::HandleActionRequest argument Code=local v = luup.variable_get(...)
luup.log("v is " .. v)

-- Picking the devices
local SENSORID= 42 -- The anti-lost sensor device ID number

-- Picking the services
local SENSERV = "urn:micasaverde-com:serviceId:HaDevice1"

luup.variable_get(SENSERV, "BatteryDate", SENSORID) <0x2f702680>

01	10/10/12 19:58:11.861	GetLuaInterface can't find device type: -1/0xc93380 str: (null) <0x2f702680>
01	10/10/12 19:58:11.862	luup_variable_get interface 0xc88030 args 0 <0x2f702680>
01	10/10/12 19:58:11.862	LuaInterface::StartEngine failed run: 0 [string "local v = luup.variable_get(...)..."]:2: attempt to concatenate local 'v' (a nil value) <0x2f702680>
01	10/10/12 19:58:11.863	JobHandler_LuaUPnP::RunLua failed: local v = luup.variable_get(...)
luup.log("v is " .. v)

-- Picking the devices
local SENSORID= 42 -- The anti-lost sensor device ID number

-- Picking the services
local SENSERV = "urn:micasaverde-com:serviceId:HaDevice1"

luup.variable_get(SENSERV, "BatteryDate", SENSORID) <0x2f702680>

Please can you help me with the log? As I have check the device number and that is correct, what am I missing?

Sadly I can’t connect via just SSH, it seems I need to use SCP, and there are no apps that provide that on the iPad as far as I know?

What does ‘ImmediatelyFlushLog’ do, other than sound like some form of toilet humour :wink:

I was on a portable device yesterday and posted only a code snippet that I thought you’d be able to work into your existing code. It wasn’t intended to be pasted into your code literally.

Here is the whole thing.

[code]-- Picking the devices
local SENSORID= 42 – The sensor device ID number

– Picking the services
local SENSERV = “urn:micasaverde-com:serviceId:HaDevice1”

local v = luup.variable_get(SENSERV, “BatteryDate”, SENSORID)
luup.log("v is " … v)
[/code]

Your next question may be about the date format. Here is a useful link.

Edit: link

Thanks futzle

Hooray! That seems to have work, it looks like it has showed the result in a line in the log .

[code]08 10/10/12 22:45:22.928 JobHandler_LuaUPnP::HandleActionRequest argument Code=-- Picking the devices
local SENSORID= 42 – The sensor device ID number

– Picking the services
local SENSERV = “urn:micasaverde-com:serviceId:HaDevice1”

local v = luup.variable_get(SENSERV, “BatteryDate”, SENSORID)
luup.log("v is " … v) <0x2eea8680>
50 10/10/12 22:45:22.929 luup_log:0: v is 1349905517 <0x2eea8680>
[/code]

How do I capture multiple lines of code to the log file so i know where they are failing or not?

Also I posted a bit of code for feedback a few days ago here →
http://forum.micasaverde.com/index.php/topic,12037.msg88327.html#msg88327 if you have chance to look at it I would really appreciate it.

Huge Thanks