We have moved at community.getvera.com

Author Topic: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices  (Read 44621 times)

Offline ttmetro

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +1/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #30 on: December 12, 2013, 12:09:14 am »
> Good job, @paulclinger, this works really well.

@RexBeckett, thank you for the feedback!

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

Output:
Code: [Select]
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?



Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #31 on: December 12, 2013, 01:39:34 am »
> 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.

@ttmetro, Thank you for the report. It seems like the IDE doesn't receive the debugging request from the device. It may happen for several reasons:

1. You have a firewall that blocks incoming connections to port 8172.

2. The IDE incorrectly detected the hostname, which is then given to the application that will connect to the IDE to start debugging. IN your case the hostname is shown as "Moncrino" (Debugger server started at Moncrino:8172.), but it's possible that this address doesn't resolve when used from the device. You can configure the hostname to use instead of auto-detected one by going to "Edit | Preferences | Settings: System" and adding

debugger.hostname = 'ip-address-of-PC-with-IDE'

Save the file and restart ZBS and then try starting the debugging again.

3. If nothing else works, it's possible that the debugger component was not correctly set on the device. You can reset the saved configuration and try to set the debugger again, which may resolve this issue. Run the following command from the Local console in ZBS (just replace 35......22 with the full number of your device):

(function() local s = ide.packages.vera:GetSettings(); s['35....22'] = nil; ide.packages.vera:SetSettings(s) end)()

You can then try the debugging again. Please let me know if one of these steps resolves the issue. I'll update the troubleshooting section in the documentation. Thank you. Paul.

Offline persimmonx

  • Full Member
  • ***
  • Posts: 116
  • Karma: +4/-5
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #32 on: December 12, 2013, 02:35:36 am »
doesn't connect to Vera:

Trying to detect Vera device address from mios.com...
Debugger server started at xxxxxxx:8172.
Connecting to Vera device at 192.168.1.101:3480...
Failed to connect to Vera device after 3 seconds.


It didn't prompt for the key.


Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #33 on: December 12, 2013, 11:50:35 am »
> Connecting to Vera device at 192.168.1.101:3480...

@persimmonx, was the address of the device detected correctly (192.168.1.101)? Can you ping that address from the computer running ZBS? At this point the IDE will attempt to contact the unit using this URL (http://192.168.1.101/cgi-bin/cmh/online_check.sh?tmp=1) and will report failure after 3s if the unit doesn't respond. You can test that URL manually and if everything works, just start the debugging again from the IDE.

> It didn't prompt for the key.

It would be the next step after the unit is detected.

Offline persimmonx

  • Full Member
  • ***
  • Posts: 116
  • Karma: +4/-5
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #34 on: December 12, 2013, 12:18:42 pm »
yes 192.168.1.101 is the address of my Vera. I ssh to Vera from the computer I am running ZBS from.
The URL you send works correctly and returns: test({"PK_AccessPoint":"30004165"});
But still IDE gives the same message and doesn't connect!

Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #35 on: December 12, 2013, 01:41:16 pm »
> yes 192.168.1.101 is the address of my Vera. I ssh to Vera from the computer I am running ZBS from.
> The URL you send works correctly and returns: test({"PK_AccessPoint":"30004165"});
> But still IDE gives the same message and doesn't connect!

That's interesting. My apologies for the inconvenience.

Can you try running the following two commands in the Local console of ZBS:

> package.path = package.path..';'..MergeFullPath(ide.editorFilename,'../lualibs/?.lua')
> require('socket.http').request('http://192.168.1.101/cgi-bin/cmh/online_check.sh?tmp=1'):match('"PK_AccessPoint":"(.+)"')

Also, what OS are you running this on?

Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #36 on: December 12, 2013, 01:48:00 pm »
@ttmetro,

> debugger.hostname = 'ip-address-of-PC-with-IDE'

I need to correct myself; the Vera component will overwrite "debugger.hostname" value with the IP address it detects based on the result of following code: "socket.dns and socket.dns.toip(socket.dns.gethostname())". Can you run it in the Local console of ZBS to see what it returns:

> socket.dns and socket.dns.toip(socket.dns.gethostname())

It should return the IP address of the computer running the IDE, but depending on your network configuration it may pick the wrong address.

Offline ttmetro

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +1/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #37 on: December 13, 2013, 09:23:52 pm »
> 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.

@ttmetro, Thank you for the report. It seems like the IDE doesn't receive the debugging request from the device. It may happen for several reasons:

1. You have a firewall that blocks incoming connections to port 8172.

Firewall was the problem.

     socket.dns and socket.dns.toip(socket.dns.gethostname())

does return the IP address of the local host.

Thanks,
Bernhard

Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #38 on: December 13, 2013, 11:21:17 pm »
> Firewall was the problem.
>   socket.dns and socket.dns.toip(socket.dns.gethostname())
> does return the IP address of the local host.

Bernhard, so are you up and running after the firewall change? Please let me know if I can help with anything else.

Paul.

Offline ttmetro

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +1/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #39 on: December 14, 2013, 10:51:38 pm »
Yes, after opening the firewall it's working fine now!

Many thanks!

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #40 on: December 16, 2013, 05:29:42 am »
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.

Offline persimmonx

  • Full Member
  • ***
  • Posts: 116
  • Karma: +4/-5
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #41 on: December 18, 2013, 02:34:40 am »
It there anyway we can ask the ZBS to detect undeclared variables at compile time?

Thanks!

Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #42 on: December 18, 2013, 10:41:02 am »
> 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: http://notebook.kulchenko.com/zerobrane/scope-aware-variable-indicators-zerobrane-studio. 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.

Offline persimmonx

  • Full Member
  • ***
  • Posts: 116
  • Karma: +4/-5
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #43 on: December 18, 2013, 06:30:33 pm »
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?

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

Offline paulclinger

  • Jr. Member
  • **
  • Posts: 84
  • Karma: +5/-0
Re: ZeroBrane Studio for Vera -- Lua IDE for debugging on Vera devices
« Reply #44 on: December 18, 2013, 09:44:21 pm »
> 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,

for i = 1, 2 do print() end

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

for _ = 1, 2 do print() end

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

for _, v in pairs(t) do print(v) end