ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices

I’ve been using ZBS to single-step through Luup code chunks prior to dropping them into plugins. It is a great way to spot those typical errors like misspelled service IDs that can be hard to track-down in running code. I think this is a really useful tool for developing Luup code for Vera scenes and plugins.

Thanks, @paulclinger, you have made the debugging process much, much easier.

It there anyway we can ask the ZBS to detect undeclared variables at compile time?

Thanks!

It there anyway we can ask the ZBS to detect undeclared variables at compile time?

@persimmonx, yes, in two ways. First of all, while you type, ZBS detects the scope (global/local) of a variable and adds an indicator to it: global variables are underlined with a solid line and local with a lightly dashed on. Screenshots and further details are in this post: Scope aware variable indicators - ZeroBrane. The page also described how you can rename local variables, show all instances, and go to definition.

The second option is to use static analyzer (Project | Analyze or Shift-F7). It does code analysis of the current file and lists all global variables used or assigned to and detects some other subtle errors as well.

Thanks, that is a life saver. I already found a couple of misspelled variables.

Why does it give a message like the following for loop variables?

unused local variable 'i'; consider removing or replacing with '_'

Why does it give a message like the following for loop variables?
unused local variable ‘i’; consider removing or replacing with ‘_’

This is when you have a loop variable that you don’t use inside the loop; for example,

[tt]for i = 1, 2 do print() end[/tt]

Since “i” is not used anywhere it gives you a warning. Just replace it with _:

[tt]for _ = 1, 2 do print() end[/tt]

The same way, if you use pairs/ipairs, but only need one value, you can do:

[tt]for _, v in pairs(t) do print(v) end[/tt]

Hello Paul,
I’m glad I’ve found your IDE for my Veralite! Thank you.

However, I have the IDE not successfully connecting :

Trying to detect Vera device address from mios.com... Debugger server started at Mac-Dusson.local:8172. Connecting to Vera device at 192.168.2.156:3480... Failed to connect to Vera device after 3 seconds.

The device ID returned by

http://192.168.2.156/cgi-bin/cmh/online_check.sh?tmp=1
is correct and I've no firewall between my Mac and the Vera.

I’m on Mac OS 10.9.1.

Thank you,

Jerome

Hi Jerome,

I’m glad I’ve found your IDE for my Veralite! Thank you.
However, I have the IDE not successfully connecting :

This may happen for two reasons:

  1. You have basic authentication enabled on your device.
  2. The address of the computer running the IDE is not correctly detected; this address is needed for the debugger to make the call from the device to the IDE to start debugging.

I have an updated version of the Vera integration code that works with basic authentication and provides a way to set the address of the IDE if it’s incorrectly detected. Please send me an email to support@zerobrane.com and I’ll send you the updated version to try. Thank you. Paul.

I just wanted to share my experience with ZeroBrane Studio’s support. I recently purchased it to do sum scripting with Vera. I had a problem connecting to my Vera because I had basic authentication enabled. Paul responded with excellent and very timely support to an email I sent (within minutes) and walked me through the issue. He has an update as noted in this thread to allow the IDE to work with basic authentication enabled and it worked well.

Just starting to use the app, but I expect it will be very helpful as I’ve found troubleshooting code on the Vera to be most tricky.

I just wanted to share my recommendation.

[quote=“ttmetro, post:31, topic:178001”][quote=“paulclinger, post:14, topic:178001”]> Good job, @paulclinger, this works really well.

@RexBeckett, thank you for the feedback![/quote]

Tried the tutorial (local sunset = luup …) but things are not working as expected.

Output:

Trying to detect Vera device address from mios.com... Debugger server started at Moncrino:8172. Connecting to Vera device at 192.168.20.13:3480... Program starting as '"C:\Programs\ZeroBraneStudioForVera\bin\lua.exe" -e "loadstring(require('mime').unb64('G0xKAQCmBGxvY2FsIHMgPSByZXF... '))()"'. Program 'lua.exe' started in 'C:\Users\Bernhard Boser\Documents\Files\Personal\Automation\Vera\plugins' (pid: 1168). Program completed in 189.65 seconds (pid: 1168).

Now way to pause or stop the program either. Just sits there, and when I already thought it was broken, it suddenly decided it was finished now. Same problem with a print statement only.

What’s wrong?[/quote]

I also tried to run the example code, but nothing worked.
I found a description for remote debugging.

There is specified that can be run using the debug code.

require (‘mobdebug’). start ()

I added code to the beginning of this line and it worked.

[quote=“paulclinger, post:17, topic:178001”]> Besides, processing credit card info requires PCI compliance, and again, users aren’t sure if the seller actually has it.

@persimmonx, I agree; it’s a valid concern. The advantage of using Stripe is that it allows me to satisfy PCI compliance without capturing and protecting CC info on my side. You (as a user) indeed can’t be sure, but you can inspect the JavaScript code to verify that I follow Stripe guidelines and don’t get CC information (not that you need to, but you could).

As to the other payment methods, I may provide Amazon payments as an alternative, but a bit later.[/quote]

This looks great, and I’d love to buy it, but I’m not buying until PayPal or Amazon payment is added. I’m just not comfortable giving my card out to a bunch of small third party services.

Hi jl8813,

This looks great, and I’d love to buy it, but I’m not buying until PayPal or Amazon payment is added. I’m just not comfortable giving my card out to a bunch of small third party services.

No problem; I sent you a PM with information on where you can send a PayPal payment.

Paul.

[quote=“paulclinger, post:51, topic:178001”]Hi jl8813,

This looks great, and I’d love to buy it, but I’m not buying until PayPal or Amazon payment is added. I’m just not comfortable giving my card out to a bunch of small third party services.

No problem; I sent you a PM with information on where you can send a PayPal payment.

Paul.[/quote]

Thanks for working with me on this! Working great!

Luup sandbox out; ZeroBraneStudio remote console in.

Good stuff! 8)

I updated the FAQ with information on how to restore debugging after a hard reset of your Vera device: Frequently Asked Questions - ZeroBrane Studio for Vera/MCV devices - Lua IDE/editor/debugger for Windows, Mac OSX, and Linux. Paul.

Recently my ZeroBrane Studio is causing a Vera restart whenever the Lua code ends - either naturally or by clicking the stop button. This happens almost every time and with even the simplest code. I am running this on a Vera3 1.5.622 with at least 40MB of free memory. For example, running this:

local v = 2

Gave this in the Output tab:

Program 'lua.exe' started in 'C:\Users\Rex\Documents\Vera\Lua' (pid: 16524). Debugging session started in 'C:\Users\Rex\Documents\Vera\Lua\'. Code execution failed. Restarting Luup engine on Vera device...........Done. Debugging session completed (traced 0 instructions). Program completed in 18.39 seconds (pid: 16524).

What can I do to fix it?

@RexBeckett,

Recently my ZeroBrane Studio is causing a Vera restart whenever the Lua code ends - either naturally or by clicking the stop button. This happens almost every time and with even the simplest code.

Are you running this using Debug or Run? Can you try Debug if you haven’t tried already as it is likely to give you the actual error message that Run doesn’t provide (as lu_action doesn’t return any results).

If that doesn’t help, can you try following the instructinos for restoring the debugging component (in the FAQ) that was posted right before your message? Please let me know if that resolved the issue. Paul.

Thanks, Paul.

I always use Debug (F5) to run the code. Where do you think the additional error information should be displayed? I also had tried: ide.packages.vera:SetSettings({regkey = ide.packages.vera:GetSettings().regkey})
in the Console but it didn’t change anything.

Trying it just now, it seems to be OK… It’s been happening for several days and now it just stopped… If it happens again, what can I capture to figure-out what is causing it?

Trying it just now, it seems to be OK… It’s been happening for several days and now it just stopped… If it happens again, what can I capture to figure-out what is causing it?

Usually, when execution fails using Run, the IDE can’t get any error information, but when using Debug you should see the error message in the Output window of the IDE.

If the opposite case happens, when the execution shows “Code execution failed.” when doing Debug, but not Run, it may mean that the debugger component is damaged or absent (for example, after a unit reset). To quickly check if it’s indeed related to the debugger component or not without using ZBS, you can try the following command in the Test Lua tab: require(‘mobdebug’).off(). If it gives you “Code execution failed.” message in the vera UI, then there is something wrong with the debugger component, in which case that command from the FAQ you showed should help.

As I’m not a programmer (sorry @Rex) I’m not up to speed with all the terms/expressions used etc, (the lingo) nor do I think my head is wired in the way it needs to be to easily grasp it and do it well, but even after saying that, I do enjoy working out the Luup code needed to do certain things with Vera. Well, I guess we all need a hook, that’ll get us into something. :wink:

So just how good is this product as a learning tool?

@Rex has just been signing it’s praises to me, but - I wanted to ask/see if there were any novices out there who’d bought it and felt that it really helped them ?

I have so many plugins I want to make, but so little time to do it, but I’m wondering if this investment will allow me to maybe realise one or two of them ?

Please let me know your thoughts…

@parkerc
I do not want to discourage you from learning more and using the same tools that developers use.

However there is a learning curve just to learn how to use an IDE (Integrated Development Environment). Many IDEs have similar organization, to make it easier for developers to work in multiple ones. In the past week alone, I have used Visual Studio IDE (Microsoft), Eclipse (Android + Java + Google App Engine), + NetBeans (Older Java) + XCode (Apple IDE). But many of the concepts will be foreign to a non developer. And even though they are all similar it often takes me a couple weeks with each to get familiar with the components in the IDE to use it effectively.

If you want to seriously develop code … than it would be a good investment in time (believe me the license fee is insignificant compared to the time commitment you will need).
If you just want to play around with LUA syntax to write a some code for conditional LUA … Install LUA for Windows. You can play around and learn the LUA language.

NOTE: An IDE does not help you learn the LUA language any faster than LUA for Windows. It can help to debug why some LUA code (that you already understand) may not be working as expected (because you forgot to handle certain boundary conditions).