I am busy with developing a lua module that can give smaller userdata responses. Developing a luup extensions is not a pretty experience to my liking. After every change you have to upload and then through a ssh connection wade through the logs. So today i thought of a hack.
I created a luup module in the same directory as my lua code. The luup module for now looks like:
-----------------------------------------------------------------------------
-- Luup debugging
-----------------------------------------------------------------------------
local string = require("string")
local table = require("table")
local base = _G
-----------------------------------------------------------------------------
-- Module declaration
-----------------------------------------------------------------------------
module("luup")
version_major = "0"
version_minor = "960"
version_branch = "dunno"
inet = {}
function inet.wget(requestString)
action = string.gsub(requestString , "192.168.81.1:49451/data_request%?id=", "") -- but uggly way of getting everything after id=
if(action=="user_data") then
return 0, '{your user_data}'
end
if (action=="user_data2") then
return 0, '{your user_data2}'
end
return -1,"not implemented"
end
function log(logString)
base.print(logString)
end
function register_handler(handlerMethod, exposeAs)
-- not implemented
end
Now most of my development can occur on my own windows machine, I can even debug normally. I hope this hack is helpfull to others.
The only things i have to solve is that in my lua code i have to remove:
luup = require(“luup”)
the module definition of my code
before uploading. I thought of the following:
if(_G["luup"]==nill) then
luup = require("luup")
module("configuration")
end
But that does not work, so if a more luup developer knows how to tackle this…
This is very interesting. I agree, the SSH and wait to read logs is a poor development environment. I’m not quite sure I understand how your module works. Is this something I upload to Vera? Please dumb it down a little for me.
I installed a lua environment on my local machine. Instead of debugging the module on your vera you can now debug locally. On my windows machine I can either use SciTech or Eclipse (note to modules need to be in the same directory as your code). A small consumer of the luup example is the following:
local json = require("json")
local luup = require("luup")
local status, rss = luup.inet.wget("192.168.81.1:49451/data_request?id=user_data")
local userData = json.decode(rss)
(note before you finally upload, local luup = require(“luup”) needs to be removed)
This decodes the userdata. Ofcourse you need to put a response in the previous code block at {your user_data}.
In my case I am developing a lua module, that gives smaller userdata responses (in size). The current userdata response is huge and contains a lot of stuff I am not interested in. Also some parts are missing that I want to have (i want to have positions on the sections, rooms and devices).
With this little trick I dont have to upload, wait until the vera is restarted. But i can just single step through my code locally and place breakpoints. This speeds up developing a module. Of course you need to test finally on the vera, but most of the bugs are ironed out by then…
The luup module I posted in my previous example is by no means complete, but good enough for my purposes. I thought more people could use this trick…
[rant]
As a side note I am not a very happy vera developer. E.g.
Try to make a small error with luup.chdev calls, this will place the vera in a commit harikiri state and it will not stop to crash, the only way out is to reset. Also the fact that one exception in a luup event or device will result in mayhem, to me it feels like not to much thought has gone into isolating these calls. I am not a very seasoned luup developer, but i would say that a device startup call should have been called with pcall and this would have been prevented… Also storing json in a luup variable (or xml) is not possible, most probably these variables should be escaped in some manner.
[/rant]
I need to correct part of my rant Also storing json in a luup variable… is not true. It just breaks in html, if you retrieve in code it works correctly… :-[
Best Home Automation shopping experience. Shop at Ezlo!