The Vera Community forums have moved!

Advanced => Programming => Scene Scripting => Topic started by: RexBeckett on March 15, 2014, 06:26:57 pm

Title: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 15, 2014, 06:26:57 pm
LuaTest is a tool for editing and testing scene Lua code. It runs on Vera as an http request handler and provides several advantages over Test Luup code (Lua):

To install LuaTest, upload the attached file RBLuaTest.lua using APPS -> Develop Apps -> Luup files -> Choose file -> GO and then restart Vera.

Enter the following code into APPS -> Develop Apps -> Test Luup code (Lua) and click GO:
Code: [Select]
local rblt = require("RBLuaTest")
rbLuaTest = rblt.rbLuaTest
luup.register_handler("rbLuaTest","LuaTest")

When used this way, the handler will work until Vera is restarted. The three lines can, alternatively, be added to Startup Lua for permanent availability.

To open a new or existing Lua file on Vera, enter:
Code: [Select]
<veraip>:3480/data_request?id=lr_LuaTest&file=<filename.lua>
Where <veraip> is the IP address of your Vera (without the <>). If <filename.lua> starts with a / it is assumed to be a full pathname otherwise it will be located in /etc/cmh-ludl/. If you do not provide a filename, the default luatest.lua will be used. If the file does not exist, it will be created when you save your code.

The following command will open LuaTest to edit the default file luatest.lua in the default folder /etc/cmh-ludl/:
Code: [Select]
<veraip>:3480/data_request?id=lr_LuaTest
Now enter your Lua code in the Code box. You can use simple copy/cut/paste commands by clicking the right mouse button.

You can use the buttons provided to create lists of the variables and actions for all the devices on your system. These are presented in a form that allows simple copy/paste into the luup.variable_get(...) and luup.call_action(...) calls in your code.

The Show Device Status button will open a new browser tab and display all variables for the specified Device Number. The values will be updated whenever the browser page is refreshed (usually F5 key). You may use the button to open pages for multiple devices.

When you have finished editing your code, click Save Code to create or update the file. Now you can click Test Code to have your code run as if it was in a scene. A new browser tab will open to show the results of the test.

Lua's print statements can be very useful when testing and debugging. With a few strategically placed in your code, you can quickly determine which sections are being executed and the value of key variables. You can leave the print statements in your code, if you wish, as Vera usually sends the output to a black hole.
 
There is now a LuaTest User Guide (https://drive.google.com/file/d/0BykZKwGsCBsATkUyaEs3QVo3ZEE/edit?usp=sharing) initiated by Tim Brien.

Edit: 18/03/2014 19:05  Version 1.1 Added edit and save functions.
Edit: 21/03/2014 11:24  Version 1.2 Minor tweaks and cleanup.
Edit: 22/03/2014 13:38  Version 1.2.1 Simplified runtime/code error messages.
Edit: 23/03/2014 14:08  Version 1.3 Added Device Variable List and Value buttons.
Edit: 24/03/2014 09:03  Version 1.4 Added Device Actions List.
Edit: 26/03/2014 09:39  Version 1.5 Added Device Status button.
Edit: 03/04/2014 13:16  Added link to User Guide.
Edit: 03/04/2014 14:26  Version 1.5.2 Allows use of pretty(...) function. See here (http://forum.micasaverde.com/index.php/topic,24018.msg168403.html#msg168403).
Edit: 20/08/2014 09:08  Version 1.6 Fixed Device Actions List for UI7.
Edit: 12/01/2018 14:00  Version 1.7 Updated for security enhancements in Vera 7.27.
Title: LuaTest 1.1 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 18, 2014, 03:10:00 pm
LuaTest 1.1 now allows you to create, edit and save Lua code as well as providing a useful test facility. See the first post for the code and instructions.

 
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 21, 2014, 07:30:02 am
LuaTest 1.2 uploaded. This is just some minor clean-up of the UI. If you modify the code, the Test Code button will not work until you have saved it. This helps to avoid the now why didn't that change fix the problem, problem.  ;)

See the first post for the code and instructions.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RichardTSchaefer on March 21, 2014, 08:13:58 am
Nice job ... do you trap/capture errors ?  That's what noobs need help with.
If you don't already you can wrap the code in pcall  and print the error.


Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 21, 2014, 08:46:47 am
Nice job ... do you trap/capture errors ?  That's what noobs need help with.
If you don't already you can wrap the code in pcall  and print the error.

Thanks, Richard. Yes I am trapping errors using xpcall so I can use my own error-handler to dump the local variables from the stack.

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on March 22, 2014, 05:13:07 am
If any of the MCV forum admins are reading this, I like to propose this be made a pinned item on this board.
 
Anything that helps people to test lua/Luup code has to be a good thing, especially when the current way via the browser is so cumbersome.

I for one love it !! :)
Title: LuaTest 1.3 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 23, 2014, 10:30:08 am
LuaTest 1.3 uploaded. I have added a couple of additional buttons:

Device Variable List opens a new browser tab and produces a list of existing variables for each device on your Vera. The serviceId and variable name are formatted as required for luup.variable_get(...) calls so may be copy/pasted straight into your code. Incorrect serviceId and variable names are one of the most common reasons why scene code fails. This should help to avoid the usual pitfalls.

Note that, just because a variable exists, it doesn't mean it is useful. Some are rarely, if ever, updated by Vera and/or plugins.

Device Variable Values is as above but also includes the current value of the variables. This can be helpful to see what your code should receive from a luup.variable_get(...) call. I made this a separate button because some device variables can have very long values which can make the listing hard to follow.

It will take a few seconds for these lists to appear after you click the buttons. The code has to run through a fairly long list of data to extract the relevant items.

See the first post for the code and instructions.
Title: LuaTest 1.4 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 24, 2014, 05:17:56 am
LuaTest 1.4 uploaded. I have added a button:

Device Action List opens a new browser tab and produces a list of possible actions for each device on your Vera. The serviceId, action name and argument list are formatted as required for the luup.call_action(...) function so may be copy/pasted straight into your code. Using an incorrect serviceId is one of the most common reasons why scene code fails. This should help to avoid that.

Note that, just because an action exists, doesn't mean it will actually do anything. The list is produced by reference to Vera's invoke function. Not all devices support the full range of actions that Vera thinks that they should.  ;)

It will take a few seconds for this list to appear after you click the button. The code has to run through a fairly long list of data to extract the relevant items.

See the first post for the code and instructions.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: C4Vette on March 26, 2014, 04:36:11 am
@RexBeckett
Just to let you know how much I appreciate this tool, although I did not have the time yet to try it. This will definitely help me learn (a little) LUA/LUUP. I do have some ideas I want to try it for: SendData to a Danfoss LC13 to send it a schedule.

Thank you!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 26, 2014, 04:56:38 am
Thanks @C4Vette. Let us know how you get on with it.

I recommend sprinkling print statements through your code so you can see which parts are working and which are not.

Code: [Select]
...
print("Initialisation done.")
...
print("Status is " .. status)
...
Title: LuaTest 1.5 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on March 26, 2014, 05:56:52 am
LuaTest 1.5 uploaded. I have added another button:

Show Device Status opens a new browser tab and shows the values of all the variables for the device specified in the Device Number field. The displayed values may be updated at any time by refreshing the browser page (usually the F5 key). You can use the button to open status pages for multiple devices.  You can also open a second page for the same device so you can compare before and after results.

To use this function directly (without needing to edit or run Lua code), enter the following in your browser:
Code: [Select]
<veraIP>:3480/data_request?id=lr_LuaTest&list=values&device=123
Replace <veraIP> with the IP address of your Vera and 123 with the number of the device to be displayed.

See the first post for the code and instructions.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: ilikelife on March 28, 2014, 01:50:08 pm
OK, I'm a noob, but this is amazing!  I agree with parkerc that it should be pinned, and i also think it should be make a permanent addition to Vera. (with a nice royalty paid to RexBeckett

I've been reading and playing and trying to code some things, but it's SO difficult to know what is going on (or what I'm doing wrong).  I've been able to accomplish things in other languages, but it helps to "see" my mistakes.  This tool allows that.  I spent most of yesterday trying things, and came back today to find a bunch of enhancements!

This is just to say THANK YOU to RexBeckett.

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on April 03, 2014, 08:20:25 am
There is now a LuaTest User Guide (https://drive.google.com/file/d/0BykZKwGsCBsATkUyaEs3QVo3ZEE/edit?usp=sharing). Credit to @Brientim for much of the preparation.
 
Title: LuaTest 1.5.2 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on April 03, 2014, 09:04:43 am
LuaTest 1.5.2 uploaded. This is a minor change to make LuaTest's pretty(...) function available to your code.

If you use Lua's print function on a table , it just shows that it is a table - which isn't much help. The function pretty(...) will expand the table and expose every element. It can be used with any type of variable but it does not expose the contents of a function, userdata or thread.

print(pretty(variable)) will print the contents of variable.
print(pretty(variable,"Name")) will print the contents of variable prefixed by Name=

See attached example.

See the first post for the code and instructions.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on May 05, 2014, 02:42:00 pm
Hi @Rex

I'm using 1.5.2 and store my test files on my NAS (so I can update them via TextTastic on the iPad)

When I click on my test URLs (e.g.)  ..

http://192.168.1.234:3480/data_request?id=lr_LuaTest&file=/nas/luatest/test.lua

it brings up the LuaTest code window with the code populated very quickly, however when I click on the Test Code button, it can freezes for a while and then not return the results page? 

I'm doing some test but wanted to make you aware just in case there was something you could think of I could look for?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on May 05, 2014, 04:12:01 pm
Quote
I'm doing some test but wanted to make you aware just in case there was something you could think of I could look for?

Your code is not ending. This could be an infinite loop or a socket call without a timeout that does not get a response. Default timeout for sockets is 0 (which means forever).
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: akbooer on June 15, 2014, 09:11:51 am
This is a brilliant addition to the Lua-user's toolbox.

I do seem to have run into trouble, though, and have narrowed it down to this one-liner example:
Code: [Select]
print (pretty {[table] = "a table index"})
...which causes a Luup restart (memory problem?)

I know that a circular structure will also break pretty, but this is not one of those.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: Grwebster on June 28, 2014, 05:54:53 pm
Sounds great and will certainly help debug. This is the kind of tool vera needs to provide to really jumpstart development.


Sent from my iPad using Tapatalk
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on July 29, 2014, 07:15:20 am
Quote
This is a brilliant addition to the Lua-user's toolbox.

Thank you, sir. I appreciate your kind words.

Quote
I do seem to have run into trouble, though, and have narrowed it down to this one-liner example:

Code: [Select]
print (pretty {[table] = "a table index"})...which causes a Luup restart (memory problem?)

That's an interesting example. The variable table is of course an existing table that contains Lua's table manipulation functions. I would imagine that Lua is trying to tell you that you cannot use it as a table index but when LuaTest tries to dump the locals off the stack for the error diagnostics, it shoots itself in the foot again. On my system (LuaTest 1.5.2) it is reported as error in error handling but it does not crash Vera. I shall have to add some logic to catch recursive errors...

print (pretty {["table"] = "a table index"}) works just fine.

Quote
I know that a circular structure will also break pretty, but this is not one of those.

pretty attempts to spot circular structures (cycles) and avoid endless loops. It works fine on sockets which contain references to themselves.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code - L_DataWatcher
Post by: REMorrison on August 04, 2014, 01:54:25 pm
I cannot find the file "L_DataWatcher" being required in the LUUP files list.  I have Vera2 with UI5 and wonder how many files are missing like this since average consumer doesn't plan to be developer.  I did upload the RBLuaTest.lua file and permanently install it.  A nudge in the right direct please?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code - L_DataWatcher
Post by: C4Vette on August 04, 2014, 03:43:04 pm
I cannot find the file "L_DataWatcher" being required in the LUUP files list.  I have Vera2 with UI5 and wonder how many files are missing like this since average consumer doesn't plan to be developer.  I did upload the RBLuaTest.lua file and permanently install it.  A nudge in the right direct please?
A nudge eh, well, I think you are asking in the wrong topic because I recognize that file as belonging to the plugin DataYours2. You can download the needed files for that plugin and upload them via the UI by choosing Apps, Develop Apps, Luup files.
But why did you put the require line there if you don't know what it is for?
Title: LuaTest under UI7
Post by: RexBeckett on August 19, 2014, 08:49:51 pm
LuaTest can be used on UI7. Almost everything works correctly. The only failure is that the Device Action List button does not work and produces a Handler failed message. I shall investigate...
Title: LuaTest 1.6 - A Tool for Testing Scene Lua Code
Post by: RexBeckett on August 20, 2014, 04:14:12 am
LuaTest 1.6 uploaded. This fixes the problem of the Device Action List button not working under UI7. This version should work on UI5, UI6 or UI7.

See the first post for the code and instructions.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: hmspain on August 25, 2014, 02:07:34 pm
OK, I'm a noob, but this is amazing!  I agree with parkerc that it should be pinned, and i also think it should be make a permanent addition to Vera. (with a nice royalty paid to RexBeckett

I've been reading and playing and trying to code some things, but it's SO difficult to know what is going on (or what I'm doing wrong).  I've been able to accomplish things in other languages, but it helps to "see" my mistakes.  This tool allows that.  I spent most of yesterday trying things, and came back today to find a bunch of enhancements!

This is just to say THANK YOU to RexBeckett.

I just stumbled across LuaTest too, and I'm looking forward to trying it.  All weekend (well a good part of it), I've been trying to figure out why my luup code was not working.  A simple luup.log("Testing to see if I see ANYTHING!") results in nada.  luup.log(test_variable) outputs a "50" line to the log, but it was painful...

The "Test Luup code" window that Vera gives you should work like LuaTest; instead you press GO and cross your fingers :-).
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on August 25, 2014, 05:38:25 pm
Quote
instead you press GO and cross your fingers :-).

That's why I created LuaTest. It's hard to write good code with your fingers crossed.  ;D
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: marcbea on October 14, 2014, 06:18:23 pm
I'm trying to run this but all i get is no handler from the url. Am i doing something wrong? I've followed all the instructions and restarted my vera. Run the code from the test luup code box but still unable to get it to load.

I'm running UI7 FW1.7.388
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on October 17, 2014, 08:51:50 am
I'm trying to run this but all i get is no handler from the url. Am i doing something wrong? I've followed all the instructions and restarted my vera. Run the code from the test luup code box but still unable to get it to load.

I'm running UI7 FW1.7.388

Do you get any error message when you run the three lines in Test Luup? It is possible that Vera is restarting after you run this code - UI7 can do that sometimes. This would lose the link to the handler. If the three lines run without error, you could place them at the end of Startup Lua so that the handler is permanently registered.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: sgs on October 24, 2014, 10:15:54 pm
Another fan of this tool here.  Up and going in minutes.
What a great way to test the logic of code you want to add to scenes, etc.

Many thanks.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on October 25, 2014, 05:28:47 am
Another fan of this tool here.  Up and going in minutes.
What a great way to test the logic of code you want to add to scenes, etc.

Many thanks.

Thanks for the feedback, @sgs. I'm glad you are finding it useful.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: Peter on October 25, 2014, 05:52:25 am
What a great tool this is Rex.
Try for a while things in lua but I never got very far. This really helps me big steps forward.

The only thing missing is to add automatic or context help on the function you are using. But I know this is asking too much.

But I'd already be very happy, with a lua help for beginners.
Or links to good help sites, with good examples as part of this tool.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on October 25, 2014, 06:21:44 am
What a great tool this is Rex.
Try for a while things in lua but I never got very far. This really helps me big steps forward.

The only thing missing is to add automatic or context help on the function you are using. But I know this is asking too much.

But I'd already be very happy, with a lua help for beginners.
Or links to good help sites, with good examples as part of this tool.

Thanks for the feedback, @Peter.

LuaTest uses a very simple browser interface. This was deliberate to allow it to be used on a variety of platforms. It does mean, though, that sophisticated options like context-sensitive help are not possible.

If you would like more advanced development and debugging aids, I recommend Zero Brane Studio for Vera (http://forum.micasaverde.com/index.php/topic,17780.0.html). This is an excellent IDE for Lua that runs the code on Vera and provides a comprehensive set of debugging tools. It does require the purchase of a subscription.

If you haven't already done so, check out the online Lua Manual (http://www.lua.org/manual/5.1/). I also recommend getting the Programming in Lua book. This is also available as a online version at http://www.lua.org/pil/ (http://www.lua.org/pil/) or as a PDF download.

I have found many useful Lua code snippets on the web. There are numerous examples on stackoverflow and github sites that come up when Googling anything that starts with Lua.

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: joer. on November 11, 2014, 10:30:17 pm
Hi,

Just wanted to say I have had my Vera for 4-5 months now.
I have been scripting lua now since then and its been painstaking if you get something wrong with vera restarts, or tweaking, and looking up variables and functions.

I downloaded this luatest tool just this week and have accomplished more and figured out some bugs and tweaks in minutes. This may be the single greatest tool I have used yet for Vera! 

Thanks again!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: JoeyD on December 18, 2014, 07:13:15 pm
I echo all the sentiments on the great utility of this tool!

Thanks RexBeckett for this (among other) contributions!!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: mdp716 on January 02, 2015, 09:18:26 pm
Rex,

It has been said before, but seriously, this is one fine piece of work.  More or less a newb to both LUA and Vera 3 and I have spent hours earlier today trying to figure out what was wrong with my "IF THEN ELSEIF THEN ELSE END" statement and was getting entirely frustrated with the response I was seeing in the log files (basically they were Microsoft answers, ...technically correct, but totally useless in solving the problem) and I nailed it in a matter of seconds using this tool.

If they don't incorporate it in the next UI release I will have to seriously question the powers that be...

Thanks so much!

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 03, 2015, 05:28:23 am
I'm glad it helped, @mdp716. Thanks for the feedback.

Quote
...they were Microsoft answers, ...technically correct, but totally useless in solving the problem...

I had a good chuckle over that. I've had a few of those from MS products.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: ntkmp42 on January 06, 2015, 08:09:28 am
Is there a URL which will allow me to run Luatest via relay instead of with local access directly to my vera's IP address?  E.g. something which I should append to the "https://vera-us-oem-relay41.mios.com..." in my browser.
Thanks!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 06, 2015, 08:59:27 am
Is there a URL which will allow me to run Luatest via relay instead of with local access directly to my vera's IP address?  E.g. something which I should append to the "https://vera-us-oem-relay41.mios.com..." in my browser.
Thanks!

I've never tried running it remotely. It seems a little risky to me to be testing scene code when you cannot see/hear what happens. I also think there is a good chance that the edit function could be compromised by running through a relay.

If you want to try it, I would expect the following to work:

Code: [Select]
https://vera-us-oem-relay41.mios.com/<verausername>/<verapassword>/<veraserial>/data_request?id=lr_LuaTest&file=<filename.lua>
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: garrettwp on January 06, 2015, 01:34:01 pm
Because you are running UI7 you will not be able to do this remotely due to the complex authentication involved.

- Garrett

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 06, 2015, 05:20:35 pm
Good point, Garrett. I failed to spot the significance of the OP's server name.  ???
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: Dav3m on January 27, 2015, 06:38:07 pm
Rex, I'll add my 2 cents to the  thread - Thanks for this awesome facility. I used it to debug some (simple) code I was writing to interface with my Ambibox (http://www.ambibox.ru/en/) TV backlight through a telnet API. It allowed me to figure out what was going on in no time, wish I'd come across it several hours earlier.

It made the difference between just giving up and even thinking of trying to turn the code into a full plugin.

Thanks!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 28, 2015, 04:50:05 am
Thanks for the feedback @Dav3m. I'm happy to hear that LuaTest is helping you make progress with your code.

If you had come across LuaTest several hours earlier, you wouldn't appreciate it as much.  ;D
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: konradwalsh on January 28, 2015, 05:53:02 am
If you had come across LuaTest several hours earlier, you wouldn't appreciate it as much.  ;D

Aint that the truth!!!!!!!!!!!!!!!!!!!
 ;D
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: kyb2012 on February 15, 2015, 11:01:42 pm
Rex, like others have said, "this is the best thing ever!"
Being able to debug by adding print statements and not having to solely rely on luup log....priceless!
Prior to this, I was hitting a wall trying to interface to my Wallyhome flood & temp sensors.  But after testing with LuaTest, I got it working in a couple hours!  Found all my mistakes.
Thanks Rex.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: NewVerdeUser on February 19, 2015, 10:51:01 pm
When I followed all of the installation instructions, the site says "No handler" when I pull it up.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: akbooer on February 20, 2015, 02:59:31 am
You have added the necessary lines in Startup Lua and saved them, and restarted?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: kyb2012 on February 20, 2015, 06:38:03 pm
Rex, is there a limit to the size of the code that I can debug in the LuaTest window?
It was working great, but as I added some more lines of code and try to save the code, I get a page error: Unable to load the web page because the server sent no data.
Error code: ERR_EMPTY_RESPONSE

I thought it was a text copy and paste issue, but even when I try typing the exact code, I get an error.

help...
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on February 21, 2015, 05:11:36 am
Quote
Rex, is there a limit to the size of the code that I can debug in the LuaTest window?

There is a limit although I have never hit it. The constraint is the maximum length of the http request supported by the browser and Vera.

You could work around this by moving any code that is already debugged to global functions in Startup Lua.
 
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: Don Diego on November 01, 2015, 12:59:32 pm
Because you are running UI7 you will not be able to do this remotely due to the complex authentication involved.

- Garrett

Rex--

  I assume this tool only works on UI7?

   Don
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: MarkAgain on November 03, 2015, 12:34:27 pm
I have been using this on UI5.  Works great!
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: sre on December 26, 2015, 03:38:45 pm
I really like this tool.  It's value to me is unexplainable.  Thanks.

i have received the value of lasttrip as : "urn:micasaverde-com:serviceId:SecuritySensor1","LastTrip"   value = "1451157523".  Can any one tell me how to conver this valus to real time ?  Regards,
 
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: akbooer on December 26, 2015, 03:47:00 pm
Code: [Select]
print (os.date("%c", value))
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: sre on October 27, 2016, 08:29:15 pm
Hi,  I have installed LUA Test and it has worked before.  But now it gives an error 'No Handler'.  Can you help me please ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: NO2nice on November 20, 2016, 09:16:44 pm
Is there a URL which will allow me to run Luatest via relay instead of with local access directly to my vera's IP address?  E.g. something which I should append to the "https://vera-us-oem-relay41.mios.com..." in my browser.
Thanks!

I've never tried running it remotely. It seems a little risky to me to be testing scene code when you cannot see/hear what happens. I also think there is a good chance that the edit function could be compromised by running through a relay.

If you want to try it, I would expect the following to work:

Code: [Select]
https://vera-us-oem-relay41.mios.com/<verausername>/<verapassword>/<veraserial>/data_request?id=lr_LuaTest&file=<filename.lua>

Hello- i didn't want to waste anyone's time here but i cannot figure out how to log into the lua test program.  when i try "<veraip>:3480/data_request?id=lr_LuaTest" it just times out.  I might be missing a fundamental frist step here but I'm usually pretty good with this stuff.  Is there an issue with U17?  Are there any good stickies to walk me through this?
thanks in advance
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: rge on January 13, 2017, 02:56:45 am
Brilliant tool, many thanks!

A suggestion - the absolute paths in the HTML aren't necessary, and prevent using the "port_3480" path instead of actual port 3480 (which is relevant for me as I have my device behind a password protected proxy).

It's simple to replace the occurrences of "/ and '/ removing the / - except the two "/ which are obviously not in HTML code - and then it works fine with the relative paths.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RobertoA109 on January 21, 2017, 03:13:11 am
Hi RexBeckett,
thank you so much for this awesome debugging tool, this is a real game changer, bringing hope and confidence.
Could you please tell me if there is a "max size limit" on the amount of Lua code that one could type in the LuaTest window?
I have tried to type in a 350 lines portion of code and it would refuse to save it.
These 350 lines are working fine if I type them in the Lua of a scene on VERA Plus running UI7 (1.7.2138).
Thank you in advance for your help and have a nice day.
Ciao
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: rge on January 24, 2017, 03:26:55 pm
Surely this thread should be a sticky?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RichardTSchaefer on January 24, 2017, 05:03:25 pm
There probably is a size limit on the HTTP - Get request used to send the info to Vera.

MCV did not support the Put request when  Rex wrote this ... a Put request does not have a size limit.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: akbooer on January 24, 2017, 05:12:42 pm
You really shouldn't try to debug 350 lines of code at a time.  If you split it up into modules it's much easier to test, document, and use.  You can incorporate as many as you like using the require keyword, or put some of the debugged code into Lua Startup.

Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RobertoA109 on February 07, 2017, 04:58:05 am
Ok, thank you. Ciao.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: sjf2626 on April 02, 2017, 03:40:48 pm
Hi,  I have installed LUA Test and it has worked before.  But now it gives an error 'No Handler'.  Can you help me please ?
I'm getting the "No Handler" message now as well.  Any ideas what might be wrong?  This was working great the last time I tried to use this a few months ago.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: iHomeCtrl on June 05, 2017, 03:38:35 pm
Does this still work with the latest UI7.  Looking for some method to test our Lua code and the built in stuff does not cut it.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: akbooer on June 05, 2017, 03:46:36 pm
It may do.  I was a huge fan of this, but now use AltUI, which is (a) fantastically better interface than UI7, and (b) is great for testing Lua code because the print statement works.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: Brientim on June 05, 2017, 03:48:10 pm
Yes, it did last time I used it.
The other option you may wish to investigate include AltUI and
https://studio.zerobrane.com/vera.html
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: iHomeCtrl on June 06, 2017, 10:32:08 am
Seems like Vera would have allot more people doing development work if they had a tools like the ZeroBrane one. 
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: rafale77 on June 06, 2017, 04:52:35 pm
It works on UI7. Been using it quite extensively myself.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: cgmartin on September 28, 2017, 09:00:30 pm
Sharing some personal modifications I made to 1.6 in case others find it useful. I've been using this in UI7:

- Added CodeMirror lua syntax highlighting editor support.
- Test results are now displayed in an iframe on the same page as the editor.

See gist: https://gist.github.com/cgmartin/d52409fe473e1d4fc5044c3d676d109c

[Edit: attached screenshot]
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on October 01, 2017, 02:28:18 pm
Hi

I?m a big user of LuaTest

Is there any reason why this should not work on UI5 too ?

Update : Answering my own question it seems to work fine in UI5 too
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on October 04, 2017, 12:31:54 pm
Hi @cgmartin

Ive noticed something strange with this version. I am a trying to save this line of code

Code: [Select]
local result = data:match "S(%d+)E" or "error"
But the plus (+) sign is removed each time ?

Code: [Select]
local result = data:match "S(%d )E" or "error"
Any ideas ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: cgmartin on October 04, 2017, 09:15:38 pm
Hi @parkerc,

I was also able to reproduce that issue from your sample code.

I found some lines from v1.6 that encode the plus "+" character into "%0F" before submitting, but weren't being decoded correctly upon receiving the request. The manual encoding seems unnecessary since the browser will urlencode the value just fine - maybe there was a bug in luup with it not urldecoding the params properly? Not sure what the history is there.

I've removed the lines doing the "+" encoding/decoding and it seems to be working better. The code has been updated in the gist link (https://gist.github.com/cgmartin/d52409fe473e1d4fc5044c3d676d109c). You can also see the diff of the changes (https://gist.github.com/cgmartin/d52409fe473e1d4fc5044c3d676d109c/revisions#diff-b7330f6f859e642870197b7c7fbbfebd) I made.

The following example is saving correctly for me now:

Code: [Select]
local data = "ZS123456EZ"
local result = data:match "S(%d+)E" or "error"
print(result)
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on October 07, 2017, 07:24:07 pm
Hi

I copied down the new file and installed it however now, when I try to save some code it adds a plus (+) into every space? E.g

If I enter this.

Code: [Select]
local code = "add anything for now"
After hitting save it goes to this..

Code: [Select]
local+code+=+"add+anything+for+now"


Is it doing that for you too ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: cgmartin on October 07, 2017, 08:13:04 pm
Quote
Is it doing that for you too ?

It's not - It is working in my tests.

This seems like a bug in UI5 that was patched in UI7 (what I'm running, version "1.7.3015"), and explains some of that code I tried removing in the previous post.

But I'm failing to understand why the original version I posted (https://gist.github.com/cgmartin/d52409fe473e1d4fc5044c3d676d109c/f65db939ff8f6726b16c623b4d070209b7a47b7c) was causing your other issue. Between 1.6 and 1.7 it should be doing the same type of encoding of the plus sign for UI5.

I don't have a way to test on UI5. You could try this modification of the original (https://gist.github.com/cgmartin/08c64c337f82dc9d45d9ea49864c2442) version I published, which does the extra "+" encoding and adds a debug log line (https://gist.github.com/cgmartin/08c64c337f82dc9d45d9ea49864c2442#file-rbluatest-lua-L260) to try and narrow down the issue. If you can try that, send me the full URL it generates in the browser address bar and the output from the log - I'll try to help.

Feel free to direct message me - we can move this out of the public forum while debugging. There will probably be a bit of back and forth.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on October 08, 2017, 06:15:20 am
Hi @cgmartin

Thanks for assisting with this. 

An interesting observation when I look in the logs is that the code being sent/tested is not showing up ?

Test code
Code: [Select]
local status, ip = luup.inet.wget("http://checkip.dyndns.org")

print (ip: match "%d+%.%d+%.%d+%.%d+")
print(string.sub(ip, -15))
print(string.sub(ip, 21))
print (ip: match "%d+%.%d+%.%d+%.%d+")
print(" ")

Will return print statements in the LuaTest UI, but nothing is in the logs to show that the code has been processed on vera? ...

Quote
Results
No errors
Runtime: 100.8 ms
Code returned: nil

Print output

/body>

     
urrent IP CheckCurrent IP Address: XXX.XXX.XXX.XXX

However the Vera luup log just shows this...

Quote
04   10/08/17 11:10:56.784    <0x2c1d7680>
50   10/08/17 11:11:11.014   luup_log:0: LuaTest No errors
Runtime:  100.8 ms
Code returned: nil <0x3053b680>

I may also have contributed to the ?+? issues as the code I was testing at the time was the following? Not sure as I?m still new to programming.

Code: [Select]
function my_escape (s)
    s = string.gsub(s, " ", "+")
    return s
end

function my_prowl (appl, event, description)
    local prowl_url      = "https://api.prowlapp.com/publicapi/add?apikey="
        .. "yourwouldputyourapikeyhere"
        .. "&application=" .. my_escape(appl)
        .. "&event="         .. my_escape(event)
        .. "&description=" .. my_escape(description)
        .. "&priority=-1"
    luup.inet.wget(prowl_url)
end

-- my_prowl (appl, event, description)
my_prowl ("Vera Home Controller", "Testing code", "this could any description")

-- luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=yourapikeyinhere&application=DSC+Security+Event&event=Armed+Notification&description=The+DSC+alarm+system+has+been+armed&priority=1")
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: cgmartin on October 10, 2017, 09:05:25 am
@parkerc

Quote
nothing is in the logs to show that the code has been processed on vera

It should log only when the "save" button is used. Your log levels seem good since you are seeing other LuaTest logs. I'm out of ideas why the log wouldn't show up.

Quote
I may also have contributed to the ?+? issues as the code I was testing at the time was the following...

That code you were testing shouldn't affect the behavior of LuaTest.

 
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on November 14, 2017, 04:55:32 am
Hi

Im not sure whats changed - maybe it?s the recent firmware updated but Ive starting to get the following Handler error when trying to access the LuaTest Url (192.168.1.183:3480/data_request?id=lr_LuaTest)

Quote
No handler

I?ve checked the start up code is still there and I have reloaded and reuploaded the RBLuatest.lua file, but still get the error? I?ve tried a reboot but no luck there either..

Does anyone have any idea what could be causing this and how to fix it?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: jswim788 on November 14, 2017, 11:20:22 am
Does your startup lua still have the code to register the handler as noted in the first post of this thread?  Maybe that got lost?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on November 14, 2017, 11:42:35 am
 Hi

Yes the code in lua start up is still there..

Code: [Select]
-- lua testing code

local rblt = require("RBLuaTest")
rbLuaTest = rblt.rbLuaTest
luup.register_handler("rbLuaTest","LuaTest")

And running this

http://192.168.1.183:3480/data_request?id=lr_LuaTest

sadly still give me a No Handler error ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: jswim788 on November 14, 2017, 12:36:35 pm
Do you see anything in the log during the start up that indicates a problem with the code you list?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on November 14, 2017, 12:43:43 pm
Good point (many thanks)

And yes checking the logs there is a huge long list of red, starting with this.

Quote
01   11/14/17 16:30:32.251   LuaInterface::LoadCode: [string "function scene_2()..."]:588: '<eof>' expected near 'end' <0x77457320>
01   11/14/17 16:30:32.379   JobHandler_LuaUPnP::Run cannot start lua with code:
function scene_2()
local host = "192.

I removed the offending code (in a scene) and it is working now, (thanks) although Im surprised I did not get any errors messages via the UI ??

I did not realise that all the lua code i have added - e.g for the start up and the scenes is loaded at once (in bulk) I assumed it was split so you would get an error if either had an issue ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: jswim788 on November 14, 2017, 05:51:46 pm
I did not realise that all the lua code i have added - e.g for the start up and the scenes is loaded at once (in bulk) I assumed it was split so you would get an error if either had an issue ?
Need someone else to answer this - I'm not familiar with the detail of the startup sequence.  I just take it for what it is and hunt down errors that I see and fix them...
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: reneboer on November 15, 2017, 08:11:44 am
Hi Parker,

I think the vera runs by all scene conditions on startup looking at the log file, so if you have LUA in a scene it will probably get loaded at startup. Other code is indeed loaded when needed.

Cheers Rene
Title: LuaTest 1.7
Post by: RexBeckett on January 12, 2018, 09:19:31 am
I have updated LuaTest to work with the new security enhancements planned for Vera 7.27. It should also work with earlier UI versions - including UI5.

The security enhancements do not permit requests in the form: http://<veraip>:3480/data_request....
Instead they must be formatted as: http://<veraip>/port_3480/data_request....

I have updated the user guide to reflect the new format for invoking LuaTest. Apart from this change, LuaTest 1.7 functions in the same way as version 1.6.

To use the new version, download it from the first post in this thread and upload it to Vera as explained in the user guide.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on January 12, 2018, 09:35:43 am
Hi @Rex !

Hope youre well.

Thanks for doing that - Ill update my install and have a play with it tonight.

QQ - Does your update also include the colour coding of words that was previously shared ?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 12, 2018, 06:57:06 pm
Hi @Rex !

Hope youre well.

Thanks for doing that - Ill update my install and have a play with it tonight.

QQ - Does your update also include the colour coding of words that was previously shared ?
Hi Chris,

Yes I'm OK, thanks. I updated my version of LuaTest code having realised that the forthcoming changes would have stopped it working. I didn't change anything else.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on January 13, 2018, 01:08:47 pm
Thanks.

As I still do most of my coding/testing on my Vera3 running UI5, that backwards compatibility is always appreciated.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: RexBeckett on January 13, 2018, 06:38:08 pm
Thanks.

As I still do most of my coding/testing on my Vera3 running UI5, that backwards compatibility is always appreciated.
If you recall, Chris, I wrote LuaTest for you and your iPad. :) I've tried to keep it compatible with just about any browser and be UI version agnostic.

I noticed that there were nearly 800 downloads of V1.6 so we seem to have helped a lot of people develop their Lua coding skills.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on August 18, 2018, 04:33:49 am
If you recall, Chris, I wrote LuaTest for you and your iPad. :) I've tried to keep it compatible with just about any browser and be UI version agnostic.

;D  Im eternally grateful for you for doing that  ;)

It should be an essential part of anyones  Lua/Vera coding tool kit..
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on August 18, 2018, 04:37:23 am
Does anyone else notice a limit on the number of lines of code you can save via LuaTest?

I use Textastic to ensure Im using the correct structure for my code, and then paste it into LuaTest to check and do minor tweaks. But Ive noticed that the more lines I try to paste it wont save - retuning a error page ?

"Safari cannot open the page as the network connection was lost?"

If I reduce the number of lines, it saves fine, no connection error screen?

As I know there should be no connection issues, could this be a memory resource issue on Vera itself ? Trying to save to much at one time , or is it  something else ? Either way any idea of a fix?
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: HSD99 on August 18, 2018, 11:13:16 am
The topic is addressed earlier in the thread.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: parkerc on August 24, 2018, 11:49:08 am
Thanks @HSD99

I had missed that.

Quote
Rex, is there a limit to the size of the code that I can debug in the LuaTest window?

There is a limit although I have never hit it. The constraint is the maximum length of the http request supported by the browser and Vera.

You could work around this by moving any code that is already debugged to global functions in Startup Lua.
Title: Re: LuaTest - A Tool for Testing Scene Lua Code
Post by: amg0 on August 24, 2018, 05:41:54 pm
FYI Altui implements this in its lua test window with a POST so no limits any more here.