We have moved at community.getvera.com

Author Topic: openLuup: debugging plugins with ZeroBrane Studio  (Read 2081 times)

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #15 on: April 29, 2018, 01:29:43 am »
My initial approach to debugging Startup Lua would be to run it first in the Lua Code Test window and sprinkle it liberally with print statements.  Within that window, the pretty() function is defined, which allows you to see the Lua structure of tables, etc...

Code: [Select]
local dev = luup.devices[2]
print "JUST PRINT()"
print(dev)
print "PRETTY PRINT()"
print (pretty(dev))

gives:

Code: [Select]
JUST PRINT()
table: 0x163738
PRETTY PRINT()
{
category_num = 0,
description = "    openLuup",
device_num_parent = 0,
device_type = "openLuup",
embedded = false,
hidden = false,
id = "",
invisible = false,
ip = "",
mac = "",
pass = "",
room_num = 0,
subcategory_num = 0,
udn = "uuid:d764c8cc-e932-55c4-478d-7aa05d83f3ea",
user = ""
}

You can't set breakpoints, but you can see what's going on.

If it's not interacting with devices, then debug the code in an IDE completely separately first.

To debug as a device then you'd need a full set of D_xxx.xml, I_xxx.xml, L_xxx.lua, ... files, with the right functionality for a device, and a global procedure for intitialisation.  It's just the name of that procedure which goes into the <startup> tag of the device file.  I simply wouldn't do this unless it's absolutely necessary.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline spilote

  • Sr. Newbie
  • *
  • Posts: 38
  • Karma: +0/-0
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #16 on: July 19, 2018, 06:20:12 pm »
Hey Guys,

I really like where this is going.

I use ZBS for Vera and love it. The main reason I'm not really deep in OpenLuup is the reason why. Since I never managed to debug within ZBS and get my global and local variables values.

I have various scene that I used and still debug via ZBS, I open the file and simply execute with a breakpoint. The workaround here seems to load the Lua engine but I simply don't understand how we can debug a single "scene" lua file.

Do we have a workaround to use ZBS for Vera with OpenLuup?

Many thanks guys!

Seb.


Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #17 on: July 20, 2018, 07:45:31 am »
I've never found a need for remote debugging, but that's probably because I simply run openLuup entirely within ZBS when developing.

Although I've not tried it, it seems to me that there's no need at all for 'ZBS for Vera', since there are comprehensive instructions here: https://studio.zerobrane.com/doc-remote-debugging and the openLuup source is entirely accessible to you.

________________

Edit: @explorer's notes, attached to an earlier post in this thread, are also quite comprehensive.
« Last Edit: July 20, 2018, 07:52:49 am by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline spilote

  • Sr. Newbie
  • *
  • Posts: 38
  • Karma: +0/-0
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #18 on: August 07, 2018, 01:49:14 pm »
Thanks Guys,

I followed the ,pdf posted on this channel. I manage to run OpenLuup in Zerobrane. What I don't understand is how to break on a scene.

As I mentioned, I'm using ZeroBrane for Vera and I use to add a break point to my .lua. Since I have a lot of global variable I used to be able to see all of them as well.

My question, let's say that I copied a scene in a .lua file, copied that in my /etc/cmh-ld, how can I break on that file?

Thanks

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #19 on: August 07, 2018, 03:35:11 pm »
What I don't understand is how to break on a scene.

As it stands, you can't.  Neither can you do that for Lua Test code.

The reason for this is that ZBS needs an actual file to trace line numbers, etc.  Scene code does not exist as a file.

However, there may be a work around...

Quote
Since I have a lot of global variable I used to be able to see all of them as well.

Scene globals exist in the same space as Lua Test code, so are available for inspection there.

Quote
My question, let's say that I copied a scene in a .lua file, copied that in my /etc/cmh-ld, how can I break on that file?

Now you're talking!  This should work, although I've never tried it with scenes.  I have tried it with plugins which, since they are a synthesis of device file XML and Lua files, suffer at the outset from the same issue.

The things to do would be to put your code into a file which you would require in Lua Test (or, indeed, Lua Startup, which also shares the same space.)

Code: [Select]
require "mySceneCode"

You should, then, be able to set breakpoints in that file and interact with them in the usual way, assuming that your actual scene Lua calls globals in the required module.

I'm off to try this for myself...
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: debugging plugins with ZeroBrane Studio
« Reply #20 on: August 07, 2018, 03:49:27 pm »
I'm off to try this for myself...

Yes!  That works just fine.

____________________

Edit: here are the various parts.

Lua Startup:
Code: [Select]
myscenes = require "myscenes"

Scene Lua:
Code: [Select]
myscenes.hello ("the","rain","in","Spain")

Lua file (myscenes.lua):
Code: [Select]
-- test scene breakpoints

local function hello (...)
  for k,v in ipairs {...} do
    print (k, tostring(v))
  end
end

return {hello = hello}

Output:
Code: [Select]
1 the
2 rain
3 in
4 Spain

And, of course, you can set a breakpoint and inspect variables in the middle of all this... (see attachment)


« Last Edit: August 08, 2018, 12:23:47 pm by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.